User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 327,694 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,679 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2079 | Replies: 5
Reply
Join Date: Mar 2008
Posts: 2
Reputation: infernodeep is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
infernodeep infernodeep is offline Offline
Newbie Poster

javascript onclick is not working in IE7 & IE6

  #1  
Mar 25th, 2008
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>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,196
Reputation: MidiMagic is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 75
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Postaholic

Re: javascript onclick is not working in IE7 & IE6

  #2  
Mar 25th, 2008
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.
Last edited by MidiMagic : Mar 25th, 2008 at 3:16 am.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Mar 2008
Posts: 2
Reputation: infernodeep is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
infernodeep infernodeep is offline Offline
Newbie Poster

Re: javascript onclick is not working in IE7 & IE6

  #3  
Mar 25th, 2008
Originally Posted by MidiMagic View Post
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
Reply With Quote  
Join Date: Mar 2008
Posts: 32
Reputation: Thirusha is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Thirusha Thirusha is offline Offline
Light Poster

Re: javascript onclick is not working in IE7 & IE6

  #4  
Mar 27th, 2008
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';
        }
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 200
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: javascript onclick is not working in IE7 & IE6

  #5  
Mar 28th, 2008
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> 
Last edited by plazmo : Mar 28th, 2008 at 9:50 am.
Reply With Quote  
Join Date: Apr 2008
Posts: 2
Reputation: aheman is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aheman aheman is offline Offline
Newbie Poster

Re: javascript onclick is not working in IE7 & IE6

  #6  
29 Days Ago
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:48 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC