PDA

View Full Version : disabling Combobox


mactaylor
09-23-2003, 09:22 PM
Afternoon,

I am trying to disable (or grey out) a javascript combobox upon a checkbox status changing to checked within an ASP page.

I know there is some type of property such as setting enabled to false but I can't seem to locate it. Your assistance is appreicated.



var cval
cval = checkbox.checked

if (cval == true) {
// Enable combobox here. Need to set to true

}
else{
// Disable combobox. Set to false
}

cheesebag
09-23-2003, 09:30 PM
Unclear whether you wanted to do this on the server (in ASP) or the client, in response to user action. The latter:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
</head>
<body>
<form>
<input type="checkbox" onclick="sel.disabled=!this.checked">___
<select name="sel" disabled="disabled">
<option>blech 1</option>
<option>blech 2</option>
<option>blech 3</option>
</select>
</form>
</body>
</html>

In ASP, you'd just be Response.Write()ing the attribute/value disabled="disabled" to the <select> tag.

mactaylor
09-23-2003, 10:29 PM
much thanks for reply, however i want it disabled if the box is unchecked, enabled if checked. How would I tweak this line to accomplish this. thanks in advance.

cheesebag
09-23-2003, 10:38 PM
Nothing like an exclamation point, among friends. ;)

[Edited the above]

cya, cb

mactaylor
09-23-2003, 11:09 PM
that works and one more...

If i wanted it load the page with the box disabled initially how would i set that?

Thanks in advance.

cheesebag
09-23-2003, 11:18 PM
<body onload="document.forms[0].reset()">

I hope you meant 'unchecked'....

mactaylor
09-24-2003, 01:40 AM
Cheesebag,

Works magnificiently. Thanks much for the assistance.