复选框和只读文本字段的数组

时间:2022-04-03 09:19:56

I have an array of checkboxes and text fields. what i want to achieve is that when the checkbox is not checked the input type text field is readonly but when the checkbox is checked, the input type text field is no longer read only.

我有一系列复选框和文本字段。我想要实现的是,当未选中复选框时,输入类型文本字段是只读的,但是当选中该复选框时,输入类型文本字段不再是只读的。

<?php 
$rsi = pg_query("Select * From items Order by name;");
while ($ri = pg_fetch_array($rsi, NULL, PGSQL_ASSOC)) {
?>
<tr>
<td align="center"><input id="item" class="input_control" type="checkbox" name="item[]" value="<?php echo $ri['item_no']; ?>"></td>
<td class="qty" align="center"><input id="quantity" type="text" name="qty[]" value="<?php echo $rsview['quantity'];?>"></td>
<td ><?php echo $ri['name']; ?></td>
<td><?php echo $ri['model']; ?></td>
<td><?php echo $ri['brand']; ?></td>
<td><?php echo $ri['item_type']; ?></td>
</tr>
<?php } ?>

1 个解决方案

#1


1  

Try This

<script type="text/javascript"> 

function toggleTB(myCheckbox){ 
    if(myCheckbox.checked){
        document.myForm.myField.disabled=1
    } 
    else{
        document.myForm.myField.disabled=0
    }
 } 
</script> 

<form name="myForm"> 
    <input type="checkbox" onClick="toggleTB(this)">
    <input type="text" name="myField" value="asdf"> 
</form>

#1


1  

Try This

<script type="text/javascript"> 

function toggleTB(myCheckbox){ 
    if(myCheckbox.checked){
        document.myForm.myField.disabled=1
    } 
    else{
        document.myForm.myField.disabled=0
    }
 } 
</script> 

<form name="myForm"> 
    <input type="checkbox" onClick="toggleTB(this)">
    <input type="text" name="myField" value="asdf"> 
</form>