[英]how to save second column value into text file from table when first column checkbox is checked?
[英]Is first value checked and second checkbox value post
function some_name() {
if (document.getElementById('first').checked)
document.getElementById('second').checked=true;
else
document.getElementById('second').checked=false;
}
<?php
$idno = $vt->veriTemizle($_GET['idno']);
$rest = $vt->sqlSorgu("Select * From rest ");
foreach($vt->fetch_assocAll() as $rest){
echo '
<input type="checkbox" name="option1[]" onclick="some_name();" id="first" value="'.$rest["price"].'" />
<input type="hidden" name="extra[]" onclick="some_name();" id="second" value="'.$rest["productname"].'-'.$rest["price"].' " />
';
}
?>
是我长期以来一直在尝试做的代码。 当点击上面列出的复选框时,我必须 select 另一个。
列出的第一个记录有效,其他记录无效
您可以为所有复选框生成 ID,并像这样解决问题
<script>
function some_name( i) {
console.log(i);
if (document.getElementById('first'+i).checked)
document.getElementById('second'+i).checked=true;
else
document.getElementById('second'+i).checked=false;
}
</script>
<?php
$row['price'] = 100;
$row['productname'] = "ABC";
$arr[] = $row;
$row['price'] = 1001;
$row['productname'] = "asd";
$arr[] = $row;
$row['price'] = 1002;
$row['productname'] = "ABC2";
$arr[] = $row;
$row['price'] = 1003;
$row['productname'] = "ABC1";
$arr[] = $row;
$i=0;
foreach($arr as $rest){
echo '
<input type="checkbox" name="option1[]" onclick="some_name('.$i.');" id="first'.$i.'" value="'.$rest["price"].'" />
<input type="checkbox" name="extra[]" onclick="some_name('.$i.');" id="second'.$i.'" value="'.$rest["productname"].'-'.$rest["price"].' " />
';
$i++;
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.