Page 1 of 1

[SOLVED] IE Code JavaScript and radio buttons checked

Posted: Sat Jun 17, 2006 3:52 pm
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.

Posted: Sat Jun 17, 2006 4:50 pm
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 :)