notonurnelly Posted July 19, 2006 Share Posted July 19, 2006 HI all,I have a list box that has the permanent numbers 0 - 9. I simply want to maintain the selected value once the form is submitted. I plan to have a test on the form that looks for fields that are not completed.The listbox at the moment is produced using an if statement. If the variable is not set the list box produces 0-9 and is fine.If the form has been submitted and a variable is sent to the listbox. It manages to show the correct selected value, but when the list box is expanded again that value is repeated 10 times instead of having 0 - 9 the value (say 3) is repeated in the list box.Here is my code hope someone can help.Many ThanksJamie print "<SELECT NAME=Q1a value=0>"; for ($i=0; $i<10; $i++){ if (isset ($Q1a)) { print "<OPTION value =$i selected>$Q1a</OPTION>"; } else { print "<OPTION value=$i>$i</OPTION>"; } } print "</SELECT><br><br>"; Quote Link to comment https://forums.phpfreaks.com/topic/15015-list-box-selected-value/ Share on other sites More sharing options...
GingerRobot Posted July 19, 2006 Share Posted July 19, 2006 [code]<?php print "<select name='Q1a' 'value'=0>"; for ($i=0; $i<10; $i++){if($Q1a == $i){echo "<option value='$i' selected = 'selected'>$i</option>";}else{ echo "<option value='$i'>$i</option>";}} print "</select>"; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15015-list-box-selected-value/#findComment-60422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.