Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2011, 10:34 PM
Authorized User
 
Join Date: Jan 2011
Posts: 11
Thanks: 4
Thanked 0 Times in 0 Posts
Default Why Doesn't This Work in IE?

Hi all,
Just wondering if anyone had any thoughts as to why this is working in IE (but works in Firefox)...

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

...

<script type="text/javascript">
function specificBoxVisible() {
	specBox = document.getElementById("specificBox");
	homeRadio = document.getElementsByName("home");
	var elementIndex;
	for (elementIndex in homeRadio) {
		if (homeRadio[elementIndex].checked) {
			if (homeRadio[elementIndex].value == "home") {
				specBox.className = "displayOff";

			} else {
			specBox.className = "displayOn";
			}
		}
	}
}
</script>

...

Specify a basic location: <input type='radio' name='home' value='home' onclick="specificBoxVisible()">Home <input type='radio' name='home' value='away' onclick="specificBoxVisible()">Out <input type='radio' name='home' value='either' onclick="specificBoxVisible()" checked='yes'>Either<br>
...as far as I know, there's nothing in there that should cause problems for IE, but it is VERY possible that I could be mistaken. Any help would be appreciated.

Thanks,
wiswif

Last edited by wiswif; August 17th, 2011 at 10:36 PM.. Reason: Forgot something
 
Old August 18th, 2011, 04:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What exactly doesn't work? Does the code not find the checked element etc. or does changing the className have no effect on the display of the element?

As an aside the code seems a little complicated. Couldn't you just pass an argument to the function and avoid the loping entirely?
__________________
Joe
http://joe.fawcett.name/
 
Old August 20th, 2011, 12:30 PM
Authorized User
 
Join Date: Jan 2011
Posts: 11
Thanks: 4
Thanked 0 Times in 0 Posts
Default

...duly noted.

Was something like this what you had in mind?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

...

<script type="text/javascript">
function specificBoxVisible(value) {
	specBox = document.getElementById("specificBox");
	if (value == "home") {
		specBox.className = "displayOff";
	} else {
		specBox.className = "displayOn";
	}
}
</script>

...

Specify a basic location: <input type='radio' name='home' value='home' onclick="specificBoxVisible('home')">Home <input type='radio' name='home' value='away' onclick="specificBoxVisible('away')">Out <input type='radio' name='home' value='either' onclick="specificBoxVisible('either')" checked='yes'>Either<br>
...tried that in both browsers and it works swimmingly. I guess for some reason when I wrote the initial version I was attracted to the idea of javascript getting the values automatically, and the previous, contrived solution was the only way I could figure to do it. (I'm sure there's a simpler way, but like I said, I couldn't find it.)

Such is one of my big problems in coding... often, I'll take a somewhat unusual route to accomplish what I desire when I can't seem to figure a quicker one that I know probably exists... I wish there were a "Code Critique" forum where people could suggest better techniques, as most of my code, though functional, would probably make more experienced programmers scratch their heads. (Is there such a forum?)

Thanks kindly,
wiswif
 
Old September 2nd, 2011, 10:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Yes (sorry for late reply, was on holiday).
__________________
Joe
http://joe.fawcett.name/
The Following User Says Thank You to joefawcett For This Useful Post:
wiswif (September 15th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
SMS API does not work online but work fine offline. Tonik Beginning PHP 1 January 4th, 2013 08:30 AM
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
why does it not work pauljames BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 January 16th, 2008 03:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.