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>

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.

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

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';
        }

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>

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.

I used the following code and it worked on IE. Mind you its for an anchor tag but it should be a general solution for other onclick events as well.

<a href="" onClick="my javascript code">My link</a>

Notice the onClick with CAPITAL "C" which did the trick in IE :)

When i replaced onclick with onClick..
It started to work for me aswell.

Thanks

Hi,
onClick() is not working for IE7.Please help.
<td width='25px'><enrgise:imgDiv name="ParentForm" title="Help"
property="butHelp" alt="Help (Alt+?)" src="help"
onClick="doBaseHelp();" /></TD>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.