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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help understanding using disabled select drop down with hidden input tag?

Status
Not open for further replies.

csphard

Programmer
Apr 5, 2002
194
0
0
US
I need to have the appropriated data selected when a screen displays. I do not want the person to beable to change this so
I will disable the select drop down.

However when the page is submitted I need to get that value.

select has a disabled but no readonly. Therefore the value is not passed

I am looking at possible solutions but what I did not know and want to varify is that
you can have a drop down (select) with a name and an hidden input tag with the same name.

Therefore upon submit the server will only receive the value from the hidden tag?

This is possible?


<form action="demo_form.asp">
<select name="sCar" disabled>
<option value="volvo" selected>Volvo</option>
<option value="saab" >Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type="hidden" name="sCar" value="volvo" ><br>
<input type="submit" value="Submit">
</form>
 
As you appear to be writing server side code to render the form, leave the select enabled but only write one option.
 
Why do you need a dropdown if you can't use it? I'd just hide the dropdown and print out a read-only textbox with the value.

In any case, yes, the hidden input will override the value from the dropdown. If at any time the Dropdown does become available the hidden input will need to be disabled or removed to get the value from the dropdown on submission of the form.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top