Page 1 of 1

[SOLVED] Submitting multiple values through 1 listbox.

Posted: Tue May 08, 2007 8:01 am
by impulse()
I'm trying to submit all selected values in a listbox which uses the following code:

Code: Select all

<form method = 'post'>
  <select name = 'ste' size = '5' multiple>
    <option value = '1'> 1
    <option value = '2'> 2
    <option value = '3'> 3
    <option value = '4'> 4
    <option value = '5'> 5
  </select>
<input type = 'submit' value = 'Boo'>
</form>
But the box only submits the last selected value. Is it possible to do what I'm asking without using checkboxes?

Regards,

Posted: Tue May 08, 2007 8:07 am
by jayshields
IIRC it should submit all the selections in an array. Are you control + clicking your options or dragging the mouse over them to ensure you have actually selected multiple options?

Edit: Might be because you haven't closed any of your option tags...

Posted: Tue May 08, 2007 8:16 am
by impulse()
I've closed the option tags but it's still only submitting the highest value.

Posted: Tue May 08, 2007 8:19 am
by CoderGoblin
try

Code: Select all

<select name = "ste[]" size="5" multiple>
Also try a var_dump of $_POST to see what you get.

Posted: Tue May 08, 2007 8:22 am
by impulse()
Thank you. The select name was wrong.

Posted: Tue May 08, 2007 8:31 am
by jayshields
I don't have access to PHP locally but it works in Javascript like this:

Code: Select all

<script type="text/javascript">
function blah() {
	for(x=0;x<3;x++) {
		if(document.ick.ste[x].selected) alert(document.ick.ste[x].value);
	}
}
</script>

<form name="ick" action="#" method="post" onSubmit="javascript:blah();">
  <select name="ste" multiple="multiple">
    <option value="one">1</option>
    <option value="two">2</option>
    <option value="three">3</option>
  </select>
<input type="submit" name="submit" value="submit">
</form> 
Edit: Yeah, what CG said! :lol: