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!

disabling 'select' menu not working on IE

Status
Not open for further replies.

ag1060

Programmer
Aug 26, 2011
27
0
0
US
Hello coders,

I have this small javascript code that works fine in chrome/firefox but won't disable the 'select' menu in IE...any suggestion? Thank you in advance.

Code:
<label>
Gender<br>
 <select name="gender" id="gender" onclick="if (this.checked) document.getElementById('org').disabled=true; else document.getElementById('org').disabled = false;" />
    <option selected>Male</option>
    <option>Female</option>
  </select></label>
<br><br><label>
<input type="checkbox" id="org" name="org" onclick="if (this.checked) document.getElementById('gender').disabled=true; else document.getElementById('gender').disabled = false;"  /></label>
This account is for an oganization / company.<br><br>
 
Hi

Better tell us your goal. For now your code is quite confusing for me, and I am sure as visitor I would find its behavior confusing too.
[ul]
[li][tt]select[/tt] elements have no [tt]checked[/tt] property.[/li]
[li]Disabling two controls on each others events usually breaks some functionality.[/li]
[/ul]

Just as a matter of readability
JavaScript:
[gray]// instead of this[/gray]
[b]if[/b] [teal]([/teal][b]this[/b][teal].[/teal]checked[teal])[/teal] document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'gender'[/i][/green][teal]).[/teal]disabled[teal]=[/teal][b]true[/b][teal];[/teal] [b]else[/b] document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'gender'[/i][/green][teal]).[/teal]disabled [teal]=[/teal] [b]false[/b][teal];[/teal]

[gray]// personally I prefer this[/gray]
document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'gender'[/i][/green][teal]).[/teal]disabled[teal]=[/teal][b]this[/b][teal].[/teal]checked

Feherke.
[link feherke.github.com/][/url]
 
Hello,

Thanks for the reply. I have added your code and works fine (except on IE 9). Here's what I was trying to do:


Basically it just disables if the menu if marked. I just want to make it work on IE9. I also use PHP to reinforce it but still nice to have the JS working on IE9.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top