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!

HTML Drop-Down menu - make readonly

Status
Not open for further replies.

firsttube

Technical User
Joined
Apr 21, 2004
Messages
165
Location
CA
I have an html <select> object that I want to make readonly when a certain hidden field's value is not null.

I've tried this:
<select name=dropdown onfocus="makeReadonly(document.thisForm.theNum.value)">


function makeReadonly(theNum) {
if (theNum != "") {
document.thisForm.dropdown.blur();
}
}

But the dropdown can still be changed.

Any ideas?

thanks


Set the gearshift for the high gear of your soul, you've got to run like an antelope, out of control.
 
if you have access to a server side language, the best thing would be to make the server send a disabled text box (or just plain text) instead of a select box if you don't want people changing it.

if you need to do it client side, you can still achieve the same results by putting a div where you want the content, and loading either a select box or a static field into its .innerHTML property in the body's onLoad event.
 
or:

function makeReadonly(theNum) {
if (theNum != "") {
document.body.focus();
}
}


Known is handfull, Unknown is worldfull
 
If you want to allow the items in the drop-down to be seen, but the selected value must remain unchanged, then set the onchange event of the SELECT list to change back to the desired value. If that value is selectedIndex=2, for example:

Code:
<select onchange='this.selectedIndex=2'>
...
</select>

That will allow dropping down, but not changing the selected value.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top