チェックボックスでチェックされた値を取得する際に問題が発生しています。コードをクリーンアップしようとしました。
選択したすべてのチェックボックスを (行ごとではなく) 選択することができました。または、行ごとにチェックボックス ID を取得できますが、選択した値は取得できません。値を別のページに転送できると確信していますが、それらを取得する方法がわかりません。
ここでの支援は大歓迎です!
//php variables used
$pages = 2
$size = 4
<form id="form" name="cb">
<div style=" width:800px; height:500px; overflow:auto">
<h2>Select Editions</h2>
<table id='table' name='table' border=1 cellpadding=7 width=50% height=50% align='center'>\n
for($x = 1; $x <= $pages; $x++) :
print "<td id='page_$x' class='page_button' align='center' custom='0' >Page $x - ";
for($i = 1; $i <= $size; $i++) :
print "<input type='checkbox' class='ebutton' id='etype_$x' name='checks[]' value='$i' /> $i";
endfor;
</td>
</tr>
//php end for loop
endfor;
</div>
</form>
チェックボックスクラスのクラスに基づいて更新するJavascriptは次のとおりです
$(document).ready(function() {
$(".ebutton").change(function() {
var idp = $(this).attr("id").split("_");
var page_num = idp[1];
// I need to find out how to get the checkboxes that are checked per row. Ex: 01,02
//var editions = ?;
//alert(editions);
var hidden_id = "#etype_page_" + page_num;
if($(hidden_id).length < 1) {
$("#base").append('<input type="hidden" id="etype_page_'+ page_num +'" name="'+ page_num +'" value="'+ editions +'" class="hidden_edtype" custom="' + editions +'">');
} else {
$(hidden_id).val($(this).val());
}
update_eShow();
});
});
function update_eShow() {
$("#eShow").html('');
$(".hidden_edtype").each(function() {
var page = $(this).attr("name");
var value = $(this).attr("custom");
$("#eShow").append('page:' + page + ' values:' + value +'<br>');
});
}
ページは次のようになります。