javascript - Change attributes dynamically using jquery -
i running loop appending input fields. now, using loop, attributes similars. so, when need grab 1 of grabbing more 1 field.
how dynamically change attributes according index, can grab correct input field ?
ebs_no = data.number_ebs; for(i=0;i<ebs_no;i++){ $('form.ebs').append("<br>ebs"+(i+1)+"</br>"); $('form.ebs').append('<br> snapshotno <input type="text" name="'+i+'"></br>'); $('form.ebs').append('<input type="submit" name="submit">'); $('[name='+i+']').on('submit',function(){ alert($('[name='+i+']').val()); }); }
replace this:
alert($('[name='+i+']').val());
by this:
alert($(this).val());
the code $(this)
refers element being treated
Comments
Post a Comment