简体   繁体   中英

How to get the dynamically created text box value in jsp using jquery javascript

I am using code in Javascript like below:

newTextBoxDiv.html('<td border="2">'+number+'</td>'
+'<td>'+grouptext+'</td>'
+'<td style="display:none">'+groupVal+'</td>'+'<td>'+itemText+'</td>'
+'<td style="display:none">'+itemId+'</td>'+'<td>'
+cuttingText+'</td>'+'<td style="display:none">'
+cuttingId+'</td>'+'<td><input type="text"
 class="ui-state-default ui-corner-all" size="6" name="textbox' 
+ counter +'" id="textbox' + counter + '" value="" size="13" ></td>'
+'<td><input type="checkbox" name="samples"/></td>'
+'<td><input type="text" class="ui-state-default
 ui-corner-all" size="8" name="textbox' + counter 
+'" id="textbox1' + counter + '" value="" size="13" >');
newTextBoxDiv.appendTo("#example");

My problem is that when I click on each row I need to get a text box value.

You can catch the click event on a table row, then use find to find the textbox among the table row's descendants:

$("tr").click(function() {
    var value = $(this).find("input[type='text']").val();
});

EDIT

Per your comment, if it's a checkbox, and you presumably want to see if it's checked:

$("tr").click(function() {
    var isChecked = $(this).find("input[type='checked']").is(":checked");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM