I am using a while loop to create a table and I am trying to pass a unique value stored in a php variable called $i
to a jquery ajax call but all I get returned it 'undefined'
.
The portion of the html table (whole table is wrapped in a div
called audit_content
which is not part of the while loop)
<tr>
<td colspan="3">
<input type="button" class="delete_submit delete_from_audit" name="image_delete" value=""
onClick="delete_image('<? echo $image_id; ?>','<? echo $audit_id; ?>')" />
<input type="button" class="reset_grade control_submit ie7_reset"
onclick="reset_image('<? echo $image_id; ?>','<? echo $audit_id; ?>')" value="" >
<input type="hidden" class="form_id" value="<? echo $i; ?>" >
<input type="button" name="audit_submit"
class="audit_submit audit_submit_btn ie7_submit" value=""; />
</td>
</tr>
the Jquery
<script>
$(document).ready(function(){
$('#audit_content').on("click", ".audit_submit", function(){
var form_id = $(this).next('.form_id').val();
alert(form_id);
//$.ajax({
//type: "POST",
//url: "ajax/image_audit.php",
//data: $('#audit_form').serialize()
//});
});
});
</script>
The .form_id
element is before the .audit_submit
button... Try prev()
instead of next()
:
var form_id = $(this).prev('.form_id').val();
You could also use siblings()
:
var form_id = $(this).siblings('.form_id').val();
<script>
$(document).ready(function(){
$(document).on("click", ".audit_submit", function(){
var form_id = $(this).next('.form_id').val();
alert(form_id);
//$.ajax({
//type: "POST",
//url: "ajax/image_audit.php",
//data: $('#audit_form').serialize()
//});
});
});
</script>
<input type="button" name="audit_submit"
class="audit_submit audit_submit_btn ie7_submit" value=""**---> ; <----** />
Why is there a semi colon ?? Php will consider it as the end of the statement.
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.