I'm using some javascript to validate my form, outputting a standard js alert whenever there's an error.
Instead of a dull old alert, could I make a DIV visible when the script finds an error?
This is my script, with onsubmit="return FormValidator(this)" being called from the Form:
<script Language="JavaScript">
function isEmailAddr(submit_by)
{
var result = false
var theStr = new String(submit_by)
var index = theStr.indexOf("@"
;
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}
function FormValidator(theForm)
{
if (theForm.submit_by.value == ""
{
alert("Please enter a value for the \"email\" field."
;
theForm.submit_by.focus();
return (false);
}
if (!isEmailAddr(theForm.submit_by.value))
{
alert("Please enter a complete email address in the form: yourname@yourdomain.com"
;
theForm.submit_by.focus();
return (false);
}
if (theForm.submit_by.value.length < 3)
{
alert("Please enter at least 3 characters in the \"email\" field."
;
theForm.submit_by.focus();
return (false);
}
return (true);
}
</script>
Instead of a dull old alert, could I make a DIV visible when the script finds an error?
This is my script, with onsubmit="return FormValidator(this)" being called from the Form:
<script Language="JavaScript">
function isEmailAddr(submit_by)
{
var result = false
var theStr = new String(submit_by)
var index = theStr.indexOf("@"
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}
function FormValidator(theForm)
{
if (theForm.submit_by.value == ""
{
alert("Please enter a value for the \"email\" field."
theForm.submit_by.focus();
return (false);
}
if (!isEmailAddr(theForm.submit_by.value))
{
alert("Please enter a complete email address in the form: yourname@yourdomain.com"
theForm.submit_by.focus();
return (false);
}
if (theForm.submit_by.value.length < 3)
{
alert("Please enter at least 3 characters in the \"email\" field."
theForm.submit_by.focus();
return (false);
}
return (true);
}
</script>