0

Hye, I have a select box with me and whenever I use a submit button only the selected value in the select box is posted. I am making a questionnaire so, I should be able to have all the entered options to be posted and not just the one on top or with the selected index.

<html>
<body>
<form action='' method='post'>
<select name='slt'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type='submit' name='sub' value='submit' />
<?php print_r($_POST); ?>
</body>
</html>

Upon post only the selected value and value of submit are posted.

3
Contributors
2
Replies
7
Views
7 Years
Discussion Span
Last Post by Wraithmanilian
0

whenever I use a submit button only the selected value in the select box is posted

That's kinda' the way it works. Why would you want to post ALL values in the list ?? You already know the values the list contains so there is no need to post them all ... just store the values and reuse them later wherever you want.

If you really MUST have them all submit (???) then try loading the values of the list into an array and submit the array with a hidden form field or do it the long way and create a hidden field for each value in the list and submit them separately.

Edited by CFROG: n/a

0

Hye, I have a select box with me and whenever I use a submit button only the selected value in the select box is posted. I am making a questionnaire so, I should be able to have all the entered options to be posted and not just the one on top or with the selected index.

<html>
<body>
<form action='' method='post'>
<select name='slt'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type='submit' name='sub' value='submit' />
<?php print_r($_POST); ?>
</body>
</html>

Upon post only the selected value and value of submit are posted.

Well, you could set the form to accept multiple choices from the given set like this:

<html>
<body>
<form action='' method='post'>
<select name="slt" size="4" multiple id="slt">
	<option value="volvo">Volvo</option>
	<option value="saab">Saab</option>
	<option value="mercedes">Mercedes</option>
	<option value="audi">Audi</option>
</select>
<input type='submit' name='sub' value='submit' />
<?php print_r($_POST); ?>
</body>
</html>

Also, if you are giving example code, please wrap it in the code tags. Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.