Option onClick in Internet Explorer

  • trotsky
  • Born
  • Born
  • No Avatar
  • Joined: Dec 02, 2005
  • Posts: 2
  • Status: Offline

Post December 2nd, 2005, 4:59 am

In a page that I am working on right now I have this problem:

I have a dropdown menu using select. This menu has two options. What I want to happen is that when I click the first option another dropdown menu (let us call it B), is disabled. And when I click the second option, menu B is enabled. I've tried to solve it this way:
Code: [ Select ]
<select name='Type'>
<option onClick='dm();' onSelect='dm();' value='DM'>Option 1</option>
<option onClick='rm();' onSelect='rm();' value='RM'>Option 2 </option>
</select>
  1. <select name='Type'>
  2. <option onClick='dm();' onSelect='dm();' value='DM'>Option 1</option>
  3. <option onClick='rm();' onSelect='rm();' value='RM'>Option 2 </option>
  4. </select>

(As you can see, I've defined both onClick and onSelect trying to make it work).

The javascript code is in a file called util.js. This is the code:
Code: [ Select ]
function dm(){
    alert("OK");
    document.newMalForm.menuB.disabled="disabled";
    return;
}

function rm(){
    alert("OK");
    document.newMalForm.menuB.disabled=false;
    return;
}
  1. function dm(){
  2.     alert("OK");
  3.     document.newMalForm.menuB.disabled="disabled";
  4.     return;
  5. }
  6. function rm(){
  7.     alert("OK");
  8.     document.newMalForm.menuB.disabled=false;
  9.     return;
  10. }


The javascript file is included using this tag:
Code: [ Select ]
<script type='text/javascript' src='util.js' language='JavaScript'></script>


Now, this works in firefox but not in IE. In fact, IE doesn't even run the functions as the alert (called in the javascript file) isn't shown when I click the menu options. What is the problem?

EDIT: The alert only exists in debug purpose. And I also wanted to say that this is my first post in this forum! :P

More editing, to clarify: newMalForm is the form that contains both of the dropdown menus.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 2nd, 2005, 4:59 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post December 2nd, 2005, 6:53 am

Remove the events from the options, use an event directly on the select instead.

Internet Explorer treats select boxes slightly different than the rest of the document, (if you've ever read anyhting about "windowed controlls" you know what I'm talking about)

I'm thinking IE doesn't notice events in childnodes of select elements, only the select elements themselves.

I normally setup my functions to work depending on either of the selects value or selectedIndex attribute & using the onchange event.

Code: [ Select ]
function this(state){
var disState = state == 1;
alert(disState);
}

...

<select onchange="this(this.selectedIndex)">
 <option>Disabled</option>
 <option>Enabled</option>
</select>
  1. function this(state){
  2. var disState = state == 1;
  3. alert(disState);
  4. }
  5. ...
  6. <select onchange="this(this.selectedIndex)">
  7.  <option>Disabled</option>
  8.  <option>Enabled</option>
  9. </select>
Strong with this one, the sudo is.
  • trotsky
  • Born
  • Born
  • No Avatar
  • Joined: Dec 02, 2005
  • Posts: 2
  • Status: Offline

Post December 2nd, 2005, 7:48 am

Thank you very much, now it works. You're quite right, IE handles things in a strange way, I've noticed.
  • djancak
  • Born
  • Born
  • No Avatar
  • Joined: Mar 01, 2012
  • Posts: 1
  • Status: Offline

Post March 1st, 2012, 7:44 am

Quote:
Now, this works in firefox but not in IE. In fact, IE doesn't even run the functions as the alert (called in the javascript file) isn't shown when I click the menu options. What is the problem?

Hello from the year 2012! Internet Explorer 10 is now out and this problem is still not fixed! Bye!

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 99 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.