Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting The Value Of A Select Box

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
I have a form at the moment with a select box, when the user hits the submit button the data goes through its checks, if the data is incorrect I must reload the form with all the values he entered still in it and display the apppropriate message of what was incorrect. Everything works fine except my select box. How do I reset the select box to the option he/she chose. I tried <select name=&quot;fruit&quot; value=&quot;$choice>[/red] but it doesn't do a thing.

Any ideas of what to do is greatly appreciated.

Sean.

top-hp1_r1_c1.gif
 
First thing you need to do is send the present form values to the loading page.

Second thing is get the value of the selected option into a variable like $val=param('fruit');

then use condition for each of the options of selection of fruit whether to display it as a checked one or an unchecked one like
if ($val='Apple')
print &quot;<option selected=\&quot;selected\&quot;>Apple&quot;;
else
print &quot;<option> Apple&quot;;

I hope this should solve your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top