I'm having a hard time with getting the value of my dynamically appended textboxes. I'm using the $.each
function to iterate all of the textboxes according to its id
and index within the id
.
<input type="text" id="student_grde_G[1]" >
<input type="text" id="student_grde_G[2]" >
<input type="text" id="student_grde_G[3]" >
<input type="button" id="save_grade_button" class="button" value="Save Grades">
jQuery:
$('#save_grade_button').click(function (){
$.each($('#student_grde_G[]'), function(i, item) {
var grade = $('#student_grde_G['+i+']').val();
alert(grade);
});
});
This doesn't work. Can anyone tell me how I can fix this?
You can just use the item parameter:
$('#save_grade_button').click(function (){
$('input[type=text]').each(function(i, item) {
var grade = $(item).val();
alert(grade);
});
});
OR with @Adil's answer combined:
$('#save_grade_button').click(function (){
$('[id^=student_grde_G]').each(function(i, item) {
var grade = $(item).val();
alert(grade);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With