Use jQuery to load a url on change of table with many input fields
I have tabled data in which most of the cells are text inputs or text areas.
Each ce开发者_StackOverflow社区ll is named with the row, then the column such as
<input type=text name=4_16>
where 4 is the row, underscore the divider, and 16 the column number
I have this javascript (using jquery)...
$(document).ready(function() {
$('#parent').change(function() {
$('#subcats').load('updatecell.php','value=' + $(this).val());
return false;
});
});
from another project. How can i modify the above to work dynamically with each cell? I will need to send the input's name (coords), and the updated value (value) to the updatecell.php. I can use name, id, or class to identify the input names if need be.
You can select all text inputs in a TD and then use 'get' to send a GET request with values in the querystring like so:
$(function() {
$('td input[type=text]').change(function() {
var coords = $(this).attr("name").split("_");
$.get('updatecell.php',{row: coords[0], col: coords[1], value: $(this).val()});
return false;
});
});
精彩评论