I'm trying to fetch dynamic input text id of dynamically created textbox but the output it is showing is undefined
Here is the code. http://jsfiddle.net/softvar/VuwXn/1/
Output should be Know my value
.
Please suggest some solutions. Badly trapped!
Thanks!
Your quotes are the problem. It has been simplified and working as below:
var variable="123";
function deleting(mynum){
alert($("input[id='"+mynum+"']").val());
}
document.getElementById("test").innerHTML= '<input type="button" value="Know my value" id="'+variable+'" class="btn btn-danger" onclick="deleting(' +variable + ')" />';
I updated your fiddle to use jquery: http://jsfiddle.net/VuwXn/12/
var variable="123";
$(document).ready(function(){
$("#test").html("<input type='button' id='"+variable+"' class='btn btn-danger' value='know my value'/>");
$("#"+variable).click(function(){
alert($(this).val());
});
});
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.