Jump to content

Archived

This topic is now archived and is closed to further replies.

dnienhaus

PHP print listbox values...?

Recommended Posts

I have some listboxes that a user will select values from and in turn it is supposed to take the selected value and print as strings to form a part number. I have all the boxes made but how can i return the value of an option selected in the list menu?

i.e. <option value="L">Clutch Pedal Assy</option>

how would i return or print to screen "L"?

Share this post


Link to post
Share on other sites
You'll want to give aname to the selectbox tag for your listboxes. then when you submit your form you use $_POSt['select_box_name']
Changing select_box_name to the name of your select box. If its a multi listbox you'll want to add [] at the name of your select box name.

Share this post


Link to post
Share on other sites
What if i have 6 listboxes and each one has a value i need returned and then the values come together to form one part number?


can i do something like "$_POST['select_box_name', 'select_box_name', 'select_box_name']"?

Share this post


Link to post
Share on other sites
In that case. Name each selectbox like this:
part[]
including the [] brackets. So you select box tag is like this:
[code]<select name="part[]">
// options here
</select>[/code]

then  use a foreach loop like so:
[code]$partNumb = '';
foreach($_POST['part] as $part_k => $part_v)
{
    $partNumb .= $part_v;
}
echo "Your partNumber is: {$partNumb}";[/code]
That will then loop through each part selectbox and generate the 6 character part number.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.