开发者

How do you manipulate form values based off local input?

开发者 https://www.devze.com 2022-12-24 07:29 出处:网络
I have a form that has a series of check boxes and some line items have a text input next to them that defines quantity of the item.

I have a form that has a series of check boxes and some line items have a text input next to them that defines quantity of the item.

<input type="checkbox"开发者_如何转开发 name="measure[][input]" value="<?=$item->id?>"> 
<input class="item_mult" type="text" name="measure[][input]" /> 

What is the best way to capture the integer from the input field and have it correspond to the check box so I can use it to calculate the total later on?


<input type="checkbox" name="measure[<?php echo $item->id; ?>][checked]" value="<?php echo $item->id; ?>"> 
<input class="item_mult" type="text" name="measure[<?php echo $item->id; ?>][input]" />

That should give the values $measure[1]['checked'] (only present if checked) and $measure[1]['input']

I corrected your short tags - they're a bad idea, as they are disabled in php by default so can cause issues if you move servers


You can give your array a name/id to associate them, just add it into the name attribute:

<input type="checkbox" name="measure[1][my_checkbox]" value="<?=$item->id?>"> 
<input class="item_mult" type="text" name="measure[1][my_text]" /> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号