[英]javascript to check checkbox when input box is ticked - checkbox array []
I have a simple javascript issue. 我有一个简单的JavaScript问题。 I have a checkbox and a input box.
我有一个复选框和一个输入框。
when the user inputs text into an input box (onkeydown) I want it to check the corresponding checkbox in the row. 当用户在输入框中输入文本时(onkeydown),我希望它选中行中的相应复选框。
My checkbox's all share the same name for an array checkbox[]
. 我的所有复选框都与数组
checkbox[]
共享相同的名称。
my simplified syntax is: 我的简化语法是:
<table>
<?php if(isset($records)) : foreach ($records as $row) : ?>
<tr>
<td>
<input type=checkbox name="editcustomer[]" id="editcustomer[]" value="<?php echo $row->id ?>">
</td>
<td>
<input type="text" name="customer_name_<?php echo $row->id ?>" id="customer_name_<?php echo $row->id ?>" value="<?php echo $row->customer_name ; ?>" onclick="document.getElementById('editcustomer<?php echo $row->id ?>').checked = true;">
</td>
<tr>
<?php endforeach ; ?>
</table>
As the name of the checkbox is not unique, only the value thereof how do I tell the javascript which checkbox to check? 由于复选框的名称不是唯一的,因此只有其值如何告诉javascript要选中哪个复选框?
<input type="text" name="customer_name_<?php echo $row->id ?>" id="customer_name_<?php echo $row->id ?>" value="<?php echo $row->customer_name ; ?>" onclick="document.getElementById('editcustomer<?php echo $row->id ?>').checked = true;">
Help appreciated as always. 帮助一如既往地受到赞赏。
Thanks 谢谢
HTML HTML
<input type="checkbox" name="checkbox[]"/>
<input type="text" name="name1" id="name1" />
<br>
<input type="checkbox" name="checkbox[]"/>
<input type="text" name="name2" id="name2" />
<br>
<input type="checkbox" name="checkbox[]" />
<input type="text" name="name3" id="name3" />
Jquery jQuery的
$(':text').change(function(){
$(this).prev(':checkbox').attr('checked','true');
});
Hope this helps. 希望这可以帮助。 Regards.
问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.