ie does not support the event of the option in select control

來源:互聯網
上載者:User
 
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:
Line number On/OffCode: Select all<select name='Type'>
<option onClick='dm();' onSelect='dm();' value='DM'>Option 1</option>
<option onClick='rm();' onSelect='rm();' value='RM'>Option 2 </option>
</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:Line number On/OffCode: Select allfunction dm(){
   alert("OK");
   document.newMalForm.menuB.disabled="disabled";
   return;
}

function rm(){
   alert("OK");
   document.newMalForm.menuB.disabled=false;
   return;
}

The javascript file is included using this tag:Line number On/OffCode: Select all<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!

More editing, to clarify: newMalForm is the form that contains both of the dropdown menus.

----Solve

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.

Line number On/OffCode: Select all

function dis(state){
var disState = state == 1;
alert(disState);
}

...

<select onchange="dis(this.selectedIndex)">
  <option>Disabled</option>
  <option>Enabled</option>
</select>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.