Reputation: 18435
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!
Upvotes: 0
Views: 2010
Reputation: 1930
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());
});
});
Upvotes: 2
Reputation: 514
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 + ')" />';
Upvotes: 3