Can someone please tell me why this form validation code is not working.
...
<Form name="theform" method="post" onSubmit="return ValidateRequiredField('theform', 'thefield', 'Works!!')" action="test2.html">
<Input type="text" name="thefield" size="20">
<input type="submit" value = "send me info">
</form>
...
<Script Language="JavaScript">
<!--
function ValidateRequiredField(formName, fieldName, message)
{
if (document.formName.fieldName.value.length < 1)
alert(message);
return false;
}
</script>
For some reason I have to pass form name, field name and message as variables. Is this the right way I am coding.
If I specify form name and field name in the code it works fine. The code below works fine:
function ValidateRequiredField()
{
if (document.theform.thefield.value.length < 1)
alert('hey this works');
return false;
}
Thanks in advance.
...
<Form name="theform" method="post" onSubmit="return ValidateRequiredField('theform', 'thefield', 'Works!!')" action="test2.html">
<Input type="text" name="thefield" size="20">
<input type="submit" value = "send me info">
</form>
...
<Script Language="JavaScript">
<!--
function ValidateRequiredField(formName, fieldName, message)
{
if (document.formName.fieldName.value.length < 1)
alert(message);
return false;
}
</script>
For some reason I have to pass form name, field name and message as variables. Is this the right way I am coding.
If I specify form name and field name in the code it works fine. The code below works fine:
function ValidateRequiredField()
{
if (document.theform.thefield.value.length < 1)
alert('hey this works');
return false;
}
Thanks in advance.