<html>
<head>
<title>test page 3</title>
<script type="text/javascript">
function validate_req (field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);
return false;
}
return true;
}
}
function validate_form(thisform)
{
with (thisform)
{
if (!validate_req(mail,"Your email is required.")) { mail.focus(); return false; }
if (!validate_req(name,"Your name is required.")) { name.focus(); return false; }
}
checkCookie()
return true;
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
{
window.open("submitted2.htm","_blank","width=400, height=200");
/* most of what I have tried to stop the form from submitting I tried here such as return false; document.action="null"; break; etc. */
}
else
{
username="name";
if (username!=null && username!="")
{
setCookie('username',username,365);
}
window.open("submited.htm","_blank","width=400, height=200");
}
}
</script>
</head>
<body>
<h1 text-align="center">Test Form 3</h1>
<hr>
<form action="mailto:" onsubmit="return validate_form(this)" method="post">
<h3>This form sends an e-mail to W3Schools.</h3>
Name:<br>
<input type="text" name="name" size="20">
<br>
Mail:<br>
<input type="text" name="mail" size="20">
<br>
Comment:<br>
<input type="text" name="comment" size="40">
<br><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
Thanks, any help would be appreciated.
This post has been edited by skwid: 21 May 2009 - 08:28 PM

New Topic/Question
Reply


MultiQuote




|