troubleshooting Question

Form validation - Javascript

Avatar of -Matthew-
-Matthew- asked on
JavaScript
3 Comments1 Solution263 ViewsLast Modified:
My script works part of the time and I don't know why, is there a better way I should be doing this.

<script type="text/javascript" language="javascript">

	function validateForm()
{
var x=document.forms["form1"]["ssn"].value
var y=document.forms["form1"]["NO_ssn"].value
if (x=="" && y=="")
  {
alert("You must type in the last four digits of your Social Security or click the 'No Social Security Number' check box.");
  return false;
  }   
}
</script>

<form  action="somewhere" method="POST" name="form1" id="form1" onsubmit="return validateForm();" >

<input  name="NO_ssn" type="checkbox" id="NO_ssn" value="N/A" />
<input name="ssn" type="text" id="ssn" value="" size="4" maxlength="4" />

</form>
ASKER CERTIFIED SOLUTION
experts1

Our community of experts have been thoroughly vetted for their expertise and industry experience.

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