get live text field data using jquery
I want to get data that user enter in the text field with name and id Name
, which has a similar structure like below;
<form id="testform" name="testform" method="post" action="process.php">
<table class="style1">
<tr>
<td class="style2">Name</td>
<td id="Name" class="style2">
<input id="Name" name="Name" type="text">
</td>开发者_运维百科;
</tr>
</table>
</form>
I want to store the data in a variable.
How can i make this possible?
Thanks in advance... :)
blasteralfred
Try this:
var nameValue = "";
$("input[id=Name]").change(function(){
nameValue = $(this).val();
});
If you can remove the id="Name" for the td (table cell) element, you can try the code given below and this will be faster compared to the previous version
var nameValue = "";
$("#Name").change(function(){
nameValue = $(this).val();
});
var contents = $("#Name").val();
Of course as a'r
very correctly points out (I missed that), you need to have the Name
id only on one element -- the text box. There's no reason to give it to the <td>
anyway.
var name = $("#Name").val();
Hmm.. too short answer :X
精彩评论