[英]submit checkbox value for the dynamic elements on html form
I have check box which will be dynamically added along with the textfields. 我有一个复选框,它将与文本字段一起动态添加。
<input type="checkbox" name="namechkbox[]">
<input type="text" name="nametxt[]">
I will need to map the checkbox value with the text field. 我将需要使用文本字段映射复选框值。 I found from other questions that after adding the hidden element over the input element checkbox.
我从其他问题中发现,在输入元素复选框上方添加了隐藏元素之后。
<input type="hidden" name=namechkbox[]" value=0>
Since it's dynamic, it will add the index because of name[] in the name. 由于它是动态的,因此将由于名称中的name []而添加索引。
What is the way to handle checkbox with value submit for the dynamic elements? 用动态元素值提交处理复选框的方法是什么?
Try this: 尝试这个:
<?php
if(isset($_POST)){
$invite = $_POST;
echo '<pre>';
print_r($invite);
}
?>
<form method="post" action="">
<?php for($i=0;$i<4;$i++)
{
?>
<input value="chkbob1" name="invite['id<?php echo $i;?>']" type="checkbox">
<input value="" name="name['id<?php echo $i;?>']" type="text">
<?php
}
?> <input type="submit">
</form>
if user checks any checkbox change the values off to on and on to off viceversa. 如果用户选中了任何复选框,则将值从关闭更改为打开,反之亦然。
for ex: 例如:
<input type="checkbox" name="namechkbox[0]" value="on" />
<input type="hidden" name="nametxt[0]" value="This my data string 1" />
<input type="checkbox" name="namechkbox[1]" value="off" />
<input type="hidden" name="nametxt[1]" value="This my data string 2" />
now you submits the from then check loop through array to check
if namechkbox[0] value is on
then take the value of nametxt[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.