JavaScript Help

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
Hey,

Struggling with some JavaScript validation for a web form.

Basically, if a checkbox is "checked" then do some validation so that the user must select one or the other radio boxes.

Checkbox - Checked THEN one of the two radio boxes below must be selected.

Radio Box
Radio Box

Looking at a dialogue box message.

Thanks,
 
Here's what I have so far.

It's the IF statement of the CHECKBOX I am missing.

So IF checkbox is "checked" then run this.

PHP:
		{
var chks = document.getElementsByName('radioboxnames');
var checkCount = 0;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
checkCount++;
}
}
if (checkCount < 1)
{
alert("Message here.");
return false;
}
		}
}
 
This doesn't seem to work.

PHP:
if (document.getElementByName('CheckBoxName').checked) {
	{
var chks = document.getElementsByName('RadioBoxNames');
var checkCount = 0;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
checkCount++;
}
}
if (checkCount < 1)
{
alert("Message here.");
return false;
}
		} }
 
Ok, I'm using the Jquery code as above, which sorta works, but it stops the form from submitting.

The validation works, but once the dialogue box is shown, the form will no longer submit.

Any ideas?

Could it be because I have existing JavaScript validation and new Jquery validation too?
 
Back
Top Bottom