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

Locking a select: Part II

Status
Not open for further replies.

TheConeHead

Programmer
Joined
Aug 14, 2002
Messages
2,106
Location
US
OK I am locking a select via:

document.forms["formb"].elements["tech"].disabled=true;

while this does lock the select - it also takes away the value of the select so when I submit the form the value t=for this select comes back "undefined" - is there any way to lock a selct but not lose the value?

[conehead]
 
You can use a hidden field to hold it.

Or

<select name="myName" onBlur="this.selectedIndex=3">

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
There's no easy "trick" to do this, but you can write up javascript to essentially do the same thing.

Here's some things you could try:
[ol]
[li]set an onfocus handler to cause the select element to lose focus (this.blur())[/li]
[li]at the time the select list is "locked", save the value to a variable, then set an onchange handler to set the list back to that value when it's changed[/li]
[li]hide the element at the time it becomes locked and display a <label> or <span> or something else in it's place, hidden elements are submitted with the page[/li]
[/ol]

While I don't really condone any of these practices, I think it's about as close as you're going to get unfortunately.....

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
There's another not-so-great way to do this: in the FORM's ONSUBMIT event, UN-disable the field.

I vote for the hidden form element though.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top