troubleshooting Question

help with javascript function

Avatar of AxISQS
AxISQS asked on
3 Comments1 Solution101 ViewsLast Modified:
I have an HTML form with some checkboxes and a couple of required fields on it.  I need the submit button to check that at least 1 checkbox is checked and the 2 required fields have values.  Right now, clicking submit doesn't do anything on the form.  Does the logic of the function and submit button look correct?

The Function:

<script type="text/javascript" language="javascript">
function validateFormFields() 
		var checkboxes=0;
        if (document.getElementsByName('_1_1_2_1') == "")
            alert('Please make a selection before submitting the form');
            return false;
        else if (document.getElementsByName('_1_1_3_1').value == "")
            alert('You must make a selection before form submission');
            return false;
		else if 		
	   	(document.getElementsByName('_1_1_62_1').checked) ||(document.getElementsByName('_1_1_61_1').checked) ||
                (document.getElementsByName('_1_1_60_1').checked) ||(document.getElementsByName('_1_1_59_1').checked) ||
                (document.getElementsByName('_1_1_57_1').checked) ||(document.getElementsByName('_1_1_56_1').checked) ||
                (document.getElementsByName('_1_1_54_1').checked) ||(document.getElementsByName('_1_1_53_1').checked) ||
                (document.getElementsByName('_1_1_52_1').checked) ||(document.getElementsByName('_1_1_51_1').checked) ||
                (document.getElementsByName('_1_1_50_1').checked) ||(document.getElementsByName('_1_1_49_1').checked) ||
                (document.getElementsByName('_1_1_48_1').checked) ||(document.getElementsByName('_1_1_47_1').checked) ||
		else if (checkboxes=0)
				alert('You must check at least one box on the form');
				return false;

The Submit Button:

<INPUT CLASS="applyButton" TYPE="BUTTON" VALUE="Submit" NAME="IgnoreMe" ONCLICK="validateFormFields();">
<INPUT CLASS="resetButton" TYPE="RESET" VALUE="Reset"> 
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros