How do you manipulate form values based off local input?

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?

Answers


<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]" /> 

Need Your Help

Flex 3: Determine if scroll panel child is visible

flex actionscript-3

Let's say I have a canvas with a fixed height and a vertical scroll bar. And the canvas has 10 children in a vertical line (like a VBox) whose combined height exceeds the height of the canvas. Base...

How do you hide the Address bar in Google Chrome for Chrome Apps?

google-chrome web-applications

I want to increase the screen real estate for my Chrome app. The Address Bar is useless in a Chrome App and I was wondering if there was a way to disable it.