this is my input field:
$("<td class='testclass'><input id='field-search' value='' type='text'></td>")
How do I get the value of the input field?
I tried it this way:
var mytest =$('#field-search').val();
alert(mytest);
The result is that I get an alert being undefined though the input field has got a value e.g. 10.
Is there a way to get the value when the value of the input field changes?
A link or an example would be very helpful. Thank you.
Link to the code: http://www.file-upload.net/download-2902420/test.use开发者_Go百科r.js.html
That's because you've not appended that html to the page. Either do that (someElement.append($("<td>...</td>"));
), or search in that part specifically
var e = $("<td class='testclass'><input id='field-search' value='1' type='text'></td>");
var mytest =e.find('#field-search').val();
alert(mytest);
You don't insert element into the page just by calling $("...")
.
In jQuery
var myVal = $('#field-search').val();
In vanilla JavaScript
var myVal = document.getElementById('field-search').value;
精彩评论