3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by McLaren
0

What are you trying to validate in the textarea? Is your business logic simply "if the textarea is not blank = OK"?

0
function ValidateContactForm()
{
	var email = document.forms["contact_form"]["email"].value;
	var atpos = email.indexOf("@");
	var dotpos = email.lastIndexOf(".");
	var message = document.forms["contact_form"]["message"].value;
	
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
	{
		Ajax("../xml/invalid_email.xml", "invalid_email");
		return false;
	}
	else if (message == null || message == "") 
	{

		Ajax("../xml/invalid_textarea.xml", "invalid_textarea");
		return false;
	}
	else
	{
		return true;	
	}
}

change the "return true" to return false at then it should not submit. After it you can add line console.log('ok') and now you can debug with firebug if you use firefox or if you use google chrome press ctrl + shift + i to open a console.

I tried submiting when email is valid but message empty and I shortly saw in console "x is not defined" and then it submitted. So I think the problem is with this line

if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)

it does not know what the x is.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.