I have a form dynamically created using Jquery and i am trying to validate the form but every time i try to get the input field value it says “undefined” , My code to get value
var username = $('#username').val();
console.log(username);
Edited : Below function will add the form field to the div.modal
function AddUserDialog(){
var temp = '<input type="text" name="username" id="username" />';
$('.modal').html(temp);
}
Thanks
Because the form is created by jquery your script can’t find it in document and will return undefined..
For such cases we have 3 functions we can use..live,delegate and on..
Read following links for more details..
Live
delegate
on