Hello I have a web site called shadygames. I want to make sure that all the information is filled out in a contact form I have set up. I am using ajax to update the page if more information is required by the user. I have the email validation working but not the textarea. Please take a look and help me out.

Thank you all at daniweb.

shadygames
contact form
javascript validation
xml files

Recommended Answers

All 3 Replies

Member Avatar for Pnorq

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

Yes, no point in sending an empty message to me.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.