A
Andrew
I've ripped off some script from another site of mine that works fine which
checks an input box to see if an email address has been entered when
submitting. If it hasn't a prompt is issued asking the user to enter an
email address.
It seems to be ignoring the validation rule and just emailing the form
anyway, can anyone help?
Below is the the relevant code -
From the <head> tag-
<SCRIPT LANGUAGE="JavaScript"> //This defines the language as javascript
<!-- hide JS code
function validateForm(form)
{
// EMAIL VALIDATION
if (!validateEMail(form.Email.value)) // is the email address valid?
{
form.Email.focus()
return false
}
if (justValidating=true) // the alert box only shows when validating, not
submitting
alert("Thank you. Your data has been validated and is ready to be
submitted.") // message shown if all data is valid
return true
}
// EMAIL VALIDATION RULES
function validateEMail(Email)
{
if (isBlank(Email)) // email blank?
{
alert("Enter your email address, please!") // return this message if it is
blank
return false
}
var atsignPos = Email.indexOf("@", 0) // check for @ sign
if (atsignPos == -1)
{
alert("Enter a valid email address with an @, please!") // return this
message if no @ sign present
return false
}
if (Email.indexOf(".", atsignPos) == -1) // check for full stop after @ sign
{
alert("Enter a valid email domain after the @, please!") //return this
message if no full stop after @ sign
return false
}
return true
}
// end JS hide -->
</SCRIPT>
And then this is the details within the form -
<form name="Validate" action="mailto:dummyemailaddress.co.uk" method="post"
onSubmit="justValidating=false; return validateForm(Validate)">
<input type="text" name="Email">
<input type="submit" name="Submit" value="Submit" ; validateForm(Validate)>
<input type="reset" name="Reset" value="Reset"></form>
Any help appreciated
Thanks
Andrew
checks an input box to see if an email address has been entered when
submitting. If it hasn't a prompt is issued asking the user to enter an
email address.
It seems to be ignoring the validation rule and just emailing the form
anyway, can anyone help?
Below is the the relevant code -
From the <head> tag-
<SCRIPT LANGUAGE="JavaScript"> //This defines the language as javascript
<!-- hide JS code
function validateForm(form)
{
// EMAIL VALIDATION
if (!validateEMail(form.Email.value)) // is the email address valid?
{
form.Email.focus()
return false
}
if (justValidating=true) // the alert box only shows when validating, not
submitting
alert("Thank you. Your data has been validated and is ready to be
submitted.") // message shown if all data is valid
return true
}
// EMAIL VALIDATION RULES
function validateEMail(Email)
{
if (isBlank(Email)) // email blank?
{
alert("Enter your email address, please!") // return this message if it is
blank
return false
}
var atsignPos = Email.indexOf("@", 0) // check for @ sign
if (atsignPos == -1)
{
alert("Enter a valid email address with an @, please!") // return this
message if no @ sign present
return false
}
if (Email.indexOf(".", atsignPos) == -1) // check for full stop after @ sign
{
alert("Enter a valid email domain after the @, please!") //return this
message if no full stop after @ sign
return false
}
return true
}
// end JS hide -->
</SCRIPT>
And then this is the details within the form -
<form name="Validate" action="mailto:dummyemailaddress.co.uk" method="post"
onSubmit="justValidating=false; return validateForm(Validate)">
<input type="text" name="Email">
<input type="submit" name="Submit" value="Submit" ; validateForm(Validate)>
<input type="reset" name="Reset" value="Reset"></form>
Any help appreciated
Thanks
Andrew