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!

How can I grey out a drop down box?? 1

Status
Not open for further replies.

WestSide2003

Technical User
Jan 22, 2003
42
0
0
US
Hi,

We have two drop down boxes in a form we are using. I want to basically grey out one of the drop down boxes if a user chooses the other.

We basically do not want a user to be able to select an option from each drop-down box at the same time. If the user chooses an option from drop-down box "A", then drop-down box "B" should be greyed out and vice versa...

Can anyone shed some light, this might be more geared to JavaScript?? I don't know JavaScript, so if there is a CF (server side) way, can someone let me know, or is this best handled with JavaScript?

Thanks

WestSide
 
like so:

Code:
<script type="text/javascript">
function doDisable(o1, o2) {
	if (o1.selectedIndex > 0) {
		o2.selectedIndex = 0;
	}
	o2.disabled = o1.selectedIndex > 0;
}
</script>

<form>
	<select name="sel1" onchange="doDisable(this, this.form.sel2);">
	<option>choose:</option>
	<option>a</option>
	<option>b</option>
	</select>

	<select name="sel2" onchange="doDisable(this, this.form.sel1);">
	<option>choose:</option>
	<option>c</option>
	<option>d</option>
	</select>
</form>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Hi,

This works, thanks for that.

However, is there a way to have box "b" lets say.. be activated if the user clicks and then box "a" be greyed out..

As of now, it works good, but I want to allow the user a way to activate box "b" by clicking it, as of now its greyed when you activate box "a",

if the user clicks the greyed box, I want to activate it, but then deactivate box "b"

 
Conceptual problem here: deactivated select box (disabled=true) stops receiving any user input (kbd, mouse).
 
vongrunt is correct, and as a user i would not expect a disabled element to become enabled by clicking on it. the first way is more logical to me.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Just a thought:

If you can only have one item selected in the 2 dropdowns at one time, is it possible for you to structure it by putting all the values in one dropdown? Dunno if that might interrupt the logical flow of your page or not.

If that's not the case you might wanna consider leading the dropdowns with a radio button. That way the user can undo one of the options that they have selected and select a value from the other dropdown instead. Something similar to this:
Code:
<html>
<head>
<title>Blah</title>
<script language=JavaScript>
function radioFunction() {
   if (blahForm.blahRadio[0].checked) {
      blahForm.blahSelect1.disabled = false;
      blahForm.blahSelect2.disabled = true;
   }
   else {
      blahForm.blahSelect1.disabled = true;
      blahForm.blahSelect2.disabled = false;
   }
}
</script>
</head>
<body>
<form name=blahForm>
<input type=radio name=blahRadio onclick='radioFunction()' checked>
<select name=blahSelect1>
<option value=1>1
<option value=2>2
</select>
<br>
<input type=radio name=blahRadio onclick='radioFunction()'>
<select name=blahSelect2 disabled>
<option value=3>3
<option value=4>4
</select>
</form>
</body>
</html>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top