you could just add the disabled attribut to the tag. or to refrence that attribute from javascript:
document.formName.selectName.disabled=true;
also, you could just remove all of the options from the list:
document.formName.selectName.options.length=0;
although i am not sure about the second one, i do know that if it works, there will not be any way to put the options back in.
hope this helps
theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
disabled only works in ie. if you set disabled = true; it will make it so that you can't use the select box at all.
i know that there are ways to take options out and add options to a select box... i just don't remember how.
jaredn has a function that does this, i'm not sure if it's an ie only solution, knowing him, it probably is, but, i'll let him post it anyways. adam@aauser.com
That's aright. I really don't need the function. I just thought that there was a fucntion that could easily make it so that selection options couldn't be selected.
didn't I say that once before?
theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
I don't want to remove options from the list. I simply want to make some options for show only. So that when the tried to submit the form on those specific options, it would alert the user that they have to select a valid option.
I have multiple selection boxes (that I want the same thing done to), so this makes that code tough to work with. Also, how do I make it so that the alert comes up? I should probably just create a function, right?
Yes Ryan, I think it will be best to write a function. This is what I could come up with in five minutes:
<script language="Javascript">
function checkSelects(form) {
select1 = form.MySelect1
select2 = form.MySelect2
if(select1.value=='x') {
alert('Select a first number please!')
return false;
}
if(select2.value=='y') {
alert('Select a second number please!')
return false;
}
return true;
}
</script>
<form>
<select name="MySelect1">
<option value="x">Select first number
<option value="x">----------------
<option>One
<option>Two
<option>Three
</select>
<select name="MySelect2">
<option value="y">Select second number
<option value="y">----------------
<option>Four
<option>Five
<option>Six
</select>
<input type="Submit" value="Submit" onClick="return checkSelects(this.form);">
</form>
Your function should be something like this. Hope this helps... <webguru>iqof188</webguru>
Ouch! I spoke too soon. It works well in IE, but of course NS encounters errors. I think it has to do with how the form is referenced within the code. It gives the following error:
That's strange, because I never typed "frm" in my code??! Are you sure you typed your own code correct? Please show your code so I can see what's wrong
<html>
<head>
<title>
disabled dropdowns
</title>
</head>
<body>
<form>
<select>
<option disabled>Please Pick a number
<option disabled>Please Pick a number
<option>One
<option>Two
<option>Three
</select>
</form>
</body>
</html>
You could always use that but it only works in Netscape 6/Mozilla. Its a standard tho -- so mabye MS will decide to implement them soon so we don't have to write javascripts for their broswer when we could just be using html . . . ===
Supports Mozilla and Web Standards
Knows HTML, XTML, CSS1, JavaScript, PHP, C++, DOM1
===
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.