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.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.