Web Hosting Talk







View Full Version : script works in FF but not IE?


LaWnForcer
01-21-2009, 12:29 AM
I use this script to set a group of icons/images and only allow the user to highlight one icon out of the group. It works perfectly in FF but not in IE. (example: gender logically the user could only select one)
<script type="text/javascript">
function submitHidden(id, value){
document.getElementById(id).value = value
var divid = id + "_" + value
var n = document.getElementsByName(id)
for(var i=0;i<n.length;i++){n[i].className = "off"}
document.getElementById(divid).className = "on"
}
</script>
<div id="gender_class_male" name="gender_class" class=""><img src="./images/male.png" alt="Male" onclick="submitHidden('gender_class', 'male');"/></div>
<div id="gender_class_female" name="gender_class" class=""><img src="./images/female.png" alt="Female" onclick="submitHidden('gender_class', 'female');"/></div>
<input type="hidden" name="gender_class_field" id="gender_class" value="">
//////////////////////////////////////////////////////////////
(When the class = "on" css places a border around the icon identifying that it is selected.)

CandyMan
01-23-2009, 07:51 AM
The last comment on the getElementsByName() method description in MSDN Library (http://msdn.microsoft.com/en-us/library/ms536438(VS.85).aspx) tells this is a bug in IE, so you'll never get it to work. You have to rewrite the script thanks to Microsoft.

LaWnForcer
01-23-2009, 01:50 PM
QUOTE "CandyMan"
"The last comment on the msdn.microsoft.com/en-us/library/ms536438(VS.85).aspx
getElementsByName() method description in MSDN Library[/URL] tells this is a bug in IE, so you'll never get it to work. You have to rewrite the script thanks to Microsoft.
/QUOTE
(Still not to 5 posts so I cant properly quote or cite the URL.)
Thank you! Thanks for the MS website with their DOM information. I never even thought about how invaluable it would be. Well back to the drawing board on my script then. Thanks for solving my problem!
If anyone has any suggestions on how to rewrite my code I would love to hear it.

CandyMan
01-27-2009, 06:09 AM
Well, the function does not return DIVs but it should return IMGs. So you don't wrap IMGs in DIVs, but assign the class names straight to images.
This is one of the possible solutions.