View Full Version : Javascript and IE 9 issue

10-29-2012, 06:49 PM

I'm having a problem with this bit of javascript code:

<script language="javascript">
function myna(){
document.getElementById("start").style.visibility = "hidden";
document.getElementById("end").style.visibility = "hidden";
document.test.start_hour[0].selected = true;
document.test.start_minute[0].selected = true;
document.test.start_half[0].selected = true;
document.test.end_hour[0].selected = true;
document.test.end_minute[0].selected = true;
document.test.end_half[0].selected = true;
document.getElementById("start").style.visibility = "visible";
document.getElementById("end").style.visibility = "visible";


It works fine in both Firefox and Chrome but not in IE 9. I would like the Start and End input fields to be hidden when the N/A checkbox is checked. However, in IE 9 the Start and End input fields are not hidden when I check the N/A checkbox. I do notice that if I click on another area of the page, the Start and End input fields become hidden. How do I get the code to properly work on IE 9?


10-29-2012, 08:16 PM

Forms should not be addressed by their name attribute, not least because they shouldn't have one.

Since you haven't shown the calling code, I would guess that you're using the onchange event, when what you need is onclick.

10-29-2012, 08:20 PM
The only thing I can think of is that myna is run onchange of something. IE 9 may be waiting for you to click elsewhere (draw focus away from the changed element) before registering the onchange event. It could easily be something else or that and something else, or several things. To really tell we would need to see the whole page.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.