最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How would I get text from an input 'type=text' element using jquery? - Stack Overflow

programmeradmin2浏览0评论

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">

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">
Share edited Sep 29, 2011 at 14:11 asked Sep 29, 2011 at 13:41 user961437user961437
Add a ment  | 

3 Answers 3

Reset to default 5

One way is

$('#Identifier').blur(function(){
    $(this).val();
});

Explanation: When the input loses focus, grab the value of the field.

Example: http://jsfiddle/4DtUh/


EDIT

As per the ments...

@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/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 plex. 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()

发布评论

评论列表(0)

  1. 暂无评论