私はこのコードに取り組んでいます!そして、私はそれを正しく行うことができませんでした。
私が欲しいのは、対応するチェックボックスがチェックされているときにテキストボックスを有効にすることです。しかし、関数を適用しても何も起こりません:(
私のコードでは、テキストとチェックボックスは php を使用してデータベースから動的に生成されます。ここに私のコードがあります:
<div><div class="ac-container">
<div id="accordion">
<?php
$qry="SELECT * FROM catalog";
$result= mysql_query($qry);
if($result){
while($info = mysql_fetch_array($result))
{
print "<h3><a href=\"\#\"> cat:".$info['name']."</a></h3><div>";
$qryitem="SELECT * FROM item WHERE Id=". $info['Cid'];
$resultitem=mysql_query($qryitem);
if($resultitem){
?>
<form name="form1" id="form" method="post" action="manage_item_action.php"  >
<?php
while($info=mysql_fetch_array($resultitem))
{
?>
<input type="checkbox"  id="checkB" name="op[]" value="<?php echo $info['Id'];?>" />   <?php echo $info['name'];?>
<label> Quantity <input disabled="disabled" id="textB" type="text" 
name="Quantit[]" value="<?php echo $info['Quantity'];?>"/>
</label>
<script>
 checkBoxes=document.form1.elements['op[]'];
 textBoxes=document.form1.elements['Quantit[]'];
 for(var i=0 ; i<checkBoxes.length;i++){
 checkBoxes[i].onchange = function() {
 textBoxes[i].disabled =!(this.checked);};
 }
 </script>
<br/>
        <?php
        } 
    }
 else echo "There are no items.";
 print "</div>";
}
}
?>
</div>
<input type="submit" value="update" name="submit"/>
<input type=reset value="clear"></td></tr> </form>