[SOLVED] IE Code JavaScript and radio buttons checked

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

[SOLVED] IE Code JavaScript and radio buttons checked

Post by Chris Corbyn »

Code: Select all

function checkForm()
{
	var checkCount = 0;
	var radios = document.getElementsByTagName('input');
	for (var x in radios)
	{
		if (radios[x].type == 'radio' && radios[x].checked)
		{
			checkCount++;
		}
	}
	if (checkCount < 19)
	{
		try {
			document.getElementById('nodey').removeChild(submitButton);
		} catch (e) {
			//
		}
	}
	else
	{
		try {
			document.getElementById('nodey').removeChild(submitButton);
		} catch (e) {
			//
		}
		document.getElementById('nodey').appendChild(submitButton);
	}
}
In Firefox this is working fine, in IE it makes it into the loop but never actually get's past that IF condition :(

Any clues?

Here's how it's being called:

Code: Select all

<div style="float: left; width: 40px; position: relative;">&nbsp;&nbsp;<input onchange="checkForm();" onclick="checkForm();" type="radio" name="question_10" value="a" /></div>
There's 19 of those, all the same but named question_1 --> question_19.
Last edited by Chris Corbyn on Sat Jun 17, 2006 4:50 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Found the cause.

FF treats the input elements as the individual elements.. IE treats them as an array for the group to which they correspond.

I just needed to loop over them if it's IE and divide my total by the number of options in that group. Works great :)
Post Reply