Johnmitchell Posted July 2, 2007 Share Posted July 2, 2007 i'm trying to say that if the text feild has nothing in it then it won't send, so it is a mandatory feild. but i can't get it to display the message i want and it's doing my nut! <script type="text/javascript"> function testcontact() { var complete=true; var emailaddress=document.theform.email.value; if ((emailaddress == "")) || ((emailaddress == null)) { window.alert('This is an ALERT ALERT ALERT!!!!'); complete=false; } return complete; </script> thats the extract of code that isn't doing anything any ideas / tips for tidying it up wouldn't go a miss either! :)cheers if you can help Link to comment Share on other sites More sharing options...
vijay Posted July 2, 2007 Share Posted July 2, 2007 Hi.... Use the following code for email validation via javascriptRegards,Vijay----------------------------------------------------------------------------------------------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>formcheck</title><script type="text/javascript"> function testcontact() { var complete=true; var emailaddress=document.theform.email.value; alert(emailaddress) if (!validateEmail(emailaddress)) { window.alert('enter valid email address'); complete=false; } return complete; } function validateEmail(email) { str=email var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i if (filter.test(str)){return true;} else return false;} </script></head><body><form name="theform" action="" id="theform" method="post" onsubmit="return testcontact()"> <input type="text" id="email" name="email" /> <input type="submit" name="submit" value="submit" /></form></body></html>---------------------------------------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.