Hello Group:
I'd be grateful to anyone who can help me with Javascript form. :-)
I want users to submit a web form, but to stop the form submission if
any of my text fields contain specific value (e.g. "http").
I incorporated "http" detection bits of script into my existing
function (only for one of my fields for now ), but for some reason this
script doesn' work, probably, because of the wrong syntax.
=============
function checkEmail(theForm)
{
// Customize these calls for your form
// Start ------->
if (!validEmail(theForm.Email,"Email Address",true))
return false;
// <--------- End
if (document.InqServicesForm.FName.value.indexOf('htt p') -1)
return false;
{
alert("http detected.");
return false;
}
return true;
}
=============
Could you please have a look at my form script?
The form's URL is here:
http://www.ccohs.ca/ccohs/inquiries_...ries_form.html
+++++++++++++++++
function isEmailAddr(Email)
{
var result = false;
var theStr = new String(Email);
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 isEmail(string) {
if (!string) return false;
var iChars = "*|,\":<>[]{}`\';()&$#%";
for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
return true;
}
function validEmail(formField,fieldLabel,required)
{
var result = true;
if (result && ((formField.value.length < 3) ||
!isEmailAddr(formField.value)))
{
alert("Please enter a complete email address in the form:
yo******@yourdomain.com");
formField.focus();
result = false;
}
return result;
}
function checkEmail(theForm)
{
// Customize these calls for your form
// Start ------->
if (!validEmail(theForm.Email,"Email Address",true))
return false;
// <--------- End
if (document.InqServicesForm.FName.value.indexOf('htt p') -1)
return false;
{
alert("http detected.");
return false;
}
return true;
}
document.forms["InqServicesForm"]
function checkForm(){
var w=document.forms["InqServicesForm"];
if(
w.FName.value == '' ||
w.LName.value == '' ||
w.Phone.value == '' ||
w.Address.value == '' ||
w.City.value == '' ||
w.Province.value == '' ||
w.PostalCode.value == '' ||
w.Email.value == ''
)
{
alert("Please fill in all required fields.");
return false;
}
return true;
}
+++++++++++++++++++
Many thanks.
O.