Solved

how can i use 'onChange' event on ie (radio and select)

Posted on 2008-10-06
4
3,219 Views
Last Modified: 2013-12-08
Hi all,

I was trying to display items dinamically in my form according to selected options in some radios and dropdown lists (<input type="radio" and select-options).

The deal is that the code i'm using works fine for firefox and safari, but under ie it doesn't.

I have different divs tags that i populate according with selected values. I'm attaching some code to show you how i'm using this.

Thx a lot for the help

Regards,

Daniel Peralta
<body>
 
<script language="JavaScript" type="text/javascript">
    function check_value(divname,variable)
    {    
        document.getElementById(divname).innerHTML= document.getElementById(variable).innerHTML;
    }
	function getSelected(newdiv,sel)
	{	
  		var value = sel.options[sel.selectedIndex].value; 		
		check_value(newdiv,value);
	}
</script>
 
<div align="left">
 
	<br />
	<input type="radio" onchange="check_value('text','a')" value="op1" name="group1" /> op1<br />
	<input type="radio" onchange="check_value('text','b')" value="op2" name="group1" /> op2<br />
	<input type="radio" onchange="check_value('text','c')" value="op3" name="group1" /> op3<br />
	<hr />
	
	<div id="text"></div>
 
	<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 
	<div id="a" visible="false">
		aaaaa<br />
	</div>
 
	<div id="b">
		bbbbb<br />
		<select id="opciones" name="opciones" onchange="getSelected('text1',this)">
			<option value="rojo">Rojo</option>
			<option value="verde">Verde</option>
			<option value="azul">Azul</option>
		</select>
		
		<div id="text1">
			otra cosa<br />
		</div>
	
	</div>
 
	<div id="c">
		ccccc<br />
	</div>
	
	<div id="rojo">
		escogio rojo<br />
	</div>
	
	<div id="verde">
		escogio verde<br />
	</div>
	
	<div id="azul">
		escogio azul<br />
	</div>
</div>
</body>

Open in new window

0
Comment
Question by:danielnp20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
wktang83 earned 500 total points
ID: 22656102
You should use the 'onclick' event instead of 'onchange'.

According to w3schools.com (http://www.w3schools.com/jsref/jsref_onchange.asp), the onchange event is only supported by the following javascript objects: fileUpload, select, text, textarea.

Therefore, the onchange event will not work with the radio object.

Use the 'onclick' event instead. It should work with IE. I tested it on IE7 and it works well. (Not sure about IE6 though).

Please let me know if you have more questions.

Regards,
wktang83
0
 

Author Closing Comment

by:danielnp20
ID: 31503490
wktang83 thx for the post, it works perfect also on ie 7 and i'll test it also in ie 6...

Finally do u know why i'm getting the message to activate 'active x' controls? and how can i disable it just to this page?

Thanks again

Regards,

Daniel Peralta
0
 
LVL 3

Expert Comment

by:wktang83
ID: 22656225
This is because you are opening the html file locally (It is stored in your computer).

If the html file is loaded from the internet it won't prompt you for the activeX control thing.

Here are some more information about this problem I found online:

This security message only occurs if you are viewing web pages directly from your hard drive. For example,C:\myFiles\myFile.htm. (Ref. 178644)

As part of the XP SP2 Local Machine zone lockdown, Internet Explorer on XP SP2 blocks active content and scripting that tries to run in the Local Machine zone. Attackers have tried to take advantage of the Local Machine zone, so Microsoft has tightened the restrictions on what can run in this zone by default.

Source: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19578
0
 

Author Comment

by:danielnp20
ID: 22656509
thx again i'll read about it
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question