DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   javascript onclick is not working in IE7 & IE6 (http://www.daniweb.com/forums/thread115562.html)

infernodeep Mar 25th, 2008 2:47 am
javascript onclick is not working in IE7 & IE6
 
hi guys ,
im facing a small problem with javascript,it works fine in FF,but inIE6 & IE7 nothing is happening could anyone solve this problem....plz help me.

Here is the HTML code:
<div id="div1" style="display: visible">Div 1</div>
<select>
<option onclick="javascript:changeDisplay('div1','block')">visible</option>
<option onclick="javascript:changeDisplay('div1','none')">hidden</option>
</select>

Here is the JavaScript code:
<script type="text/javascript">
function changeDisplay(elem,displayMode){
document.getElementById(elem).style.display = displayMode;
}
</script>

MidiMagic Mar 25th, 2008 3:09 am
Re: javascript onclick is not working in IE7 & IE6
 
If the script keeps running (e.g. if there is a loop we can't see, or another script), the display won't change. IE waits until the script ends to update the screen.

Block and none are not valid display modes. Use visible and hidden.

infernodeep Mar 25th, 2008 3:36 am
Re: javascript onclick is not working in IE7 & IE6
 
Quote:

Originally Posted by MidiMagic (Post 568538)
If the script keeps running (e.g. if there is a loop we can't see, or another script), the display won't change. IE waits until the script ends to update the screen.

Block and none are not valid display modes. Use visible and hidden.



thank u for response
but still it's not working...
if possible can u send me the code plz its urgent
once again thank u

Thirusha Mar 27th, 2008 8:18 am
Re: javascript onclick is not working in IE7 & IE6
 
i have used none and single quotes and it works in both IE and firefox
like this

        var el = document.getElementById(obj);
        var butId = document.getElementById(buttonId);
        if ( el.style.display != 'none' )
        {
                el.style.display = 'none';
                butId.value='Show Filter';
                document.getElementById("FilterResultsList").style.display = '';
        }else {
                el.style.display = '';
                butId.value='Hide Filter';
                document.getElementById("FilterResultsList").style.display = 'none';
        }

plazmo Mar 28th, 2008 9:49 am
Re: javascript onclick is not working in IE7 & IE6
 
the problem is you cant put an event on a option in IE as far as i know.
so the best solution is to put the event on the select
<div id="div1" style="display: visible">Div 1</div>
<select  onchange="changeDisplay('div1',this.options[this.selectedIndex].value)">
<option value="block">visible</option>
<option value="none">hidden</option>
</select>

aheman Apr 10th, 2008 11:07 am
Re: javascript onclick is not working in IE7 & IE6
 
plazmo is right about that. In IE6/7 (no idea about later versions) options can't really have individual onclick statements. However, a quick workaround can be put together.

Starting code...
<select>
    <option onclick="my javascript"></option>
    <option onclick="my javascript"></option>
    <option onclick="my javascript"></option>
</select>

In order to get that working, just change the onclicks to values, and add the onchange handler eval(this.value) and it will function almost identical to an onclick.

<select onchange="eval(this.value);">
    <option value="my javascript"></option>
    <option value="my javascript"></option>
    <option value="my javascript"></option>
</select>

It's the fastest way I know to make option onclick work in IE and Mozilla.


All times are GMT -4. The time now is 12:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC