How would I get text from an input 'type=text' element using jquery?
Provided I cannot edit the HTML code at all how开发者_开发百科 would I do this?
<input type="text" id="Identifier"
class="inputControlFlexWidth" value="" tabindex="9" size="25"
name="texthole">
I'm guessing this has to be a timed event such as
setInterval(ObserveInputValue(), 100);
Because the input can happen at any time.
I then want to use this text to update a URL.
Thanks.
Edit:
<input id="ServiceRequestEditForm.CustomObject6 Name.hidden" type="hidden" value=""
tabindex="-1" name="ServiceRequestEditForm.CustomObject6 Name.hidden">
One way is
$('#Identifier').blur(function(){
$(this).val();
});
Explanation: When the input loses focus, grab the value of the field.
Example: http://jsfiddle.net/4DtUh/
EDIT
As per the comments...
@Interstellar_Coder is right about spaces inside the id
.
So, instead of using the id
as the "hook", you could use the name
attribute:
$('input[name="ServiceRequestEditForm.CustomObject6 Name.hidden"]')
Example 2: http://jsfiddle.net/4DtUh/10/
You can add an event listener for the change
event, then do whatever you need to in there.
$('#Identifier').change(function(){
//do whatever you need to
});
No, nothing so complex. You can just use .val()
to get the value. In your code you would do:
$('#Identifier').val()
Take a look at the documentation for val()
精彩评论