PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue May 08, 2007 8:01 am
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,
Last edited by
impulse() on Tue May 08, 2007 8:22 am, edited 1 time in total.
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Tue May 08, 2007 8:07 am
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...
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue May 08, 2007 8:16 am
I've closed the option tags but it's still only submitting the highest value.
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Tue May 08, 2007 8:19 am
try
Code: Select all
<select name = "ste[]" size="5" multiple>
Also try a var_dump of $_POST to see what you get.
impulse()
Forum Regular
Posts: 748 Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:
Post
by impulse() » Tue May 08, 2007 8:22 am
Thank you. The select name was wrong.
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Tue May 08, 2007 8:31 am
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!