NoraWil
asked on
How to set value to dropdown list
Hi experts,
I'm new at php. I'm trying to create form that uses some dropdown menu/lists to let the user choose between a handful options. There are also quite a few text fields on the form.
Everything works perfect as long as the user fills in all the fields en lists. When the users clicks on 'submit' without filling in all text boxes en lists, I want to show exactly the same form as it was before pressing the 'submit' button.
This works perfect for all my text boxes, but all lists are reset.
I have collected the values of all contents in the dropdown lists with
$rubriek = $_POST["rubriek"];
$rubriek2 = $_POST["rubriek2"];
When a submit failed, echo $rubriek; shows the correct choice of the user, but the dropdown list shows the first option again.
How can I set the value of the dropdown list to $rubriek??
I tried things like
form.rubriek.text = $rubriek;
of
form.rubriek.value=$rubrie k;
but that doesn't do anything.
I can do the trick in Javascript, but that is not what I want.
I'm new at php. I'm trying to create form that uses some dropdown menu/lists to let the user choose between a handful options. There are also quite a few text fields on the form.
Everything works perfect as long as the user fills in all the fields en lists. When the users clicks on 'submit' without filling in all text boxes en lists, I want to show exactly the same form as it was before pressing the 'submit' button.
This works perfect for all my text boxes, but all lists are reset.
I have collected the values of all contents in the dropdown lists with
$rubriek = $_POST["rubriek"];
$rubriek2 = $_POST["rubriek2"];
When a submit failed, echo $rubriek; shows the correct choice of the user, but the dropdown list shows the first option again.
How can I set the value of the dropdown list to $rubriek??
I tried things like
form.rubriek.text = $rubriek;
of
form.rubriek.value=$rubrie
but that doesn't do anything.
I can do the trick in Javascript, but that is not what I want.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, this does the job.
Usually you will have something like this
<select name="whatever">
if(isset($whatever)){echo "<option value=\"$whatever\">$whate
then the regular list of options
</select>