[英]I have created a dynamic checkbox using php, but when i use .checked() to check it, only first radio button is checked. how to check the rest?
<div id="pop2" class="box2" style="display: none">
<form action="" method="post">
<div class="second" style="margin-top:3px;margin-left:10px;font-size:100%">Add to</div>
<?php
$new2=array();
$new2=getlist();
foreach($new2 as $value){
echo'<input type="radio" id="qwerty" name="qwerty" value="'.$value.'" onclick="theLast()" />';
echo"$value";echo"<br>";}
?>
<hr>
<button type="button" id="add2" class="new" onclick="theFinal()" >Create new list</button>
</form>
</div>
and i used javascript to check in theLast() function 我用JavaScript来检查theLast()函数
if (document.getElementById('qwerty').checked) {
window.lists=document.getElementById('qwerty').value;
}
only first radio button is working fine, rest are not detected in .checked() 只有第一个单选按钮可以正常工作,.checked()中未检测到其余按钮
Having the same id
attribute for all the checkboxes can cause these kinds of issues. 所有复选框具有相同的id
属性可能会导致此类问题。 I would suggest using a commom class instead and iterating the checkboxes using the getElementByClassName function to check for "checked" boxes. 我建议改用commom类,并使用getElementByClassName函数迭代复选框以检查“已选中”复选框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.