Here is the code:
[HTML] <html>
<head>
<script type="text/Javascript">
[/HTML]
Expand|Select|Wrap|Line Numbers
- function validate() {
- var fname = String(document.myForm.Fname.value);
- var lname = String(document.myForm.Lname.value);
- var email = String(document.myForm.myEmail.value);
- var username = Fname +""+ Lname;
- var msg = "Thank you for visiting again.";
- var err = false;
- if ((fname.length == 0)||(lname.length == 0)||(email.length==0)){
- msg = "Please enter information in all three fields";
- err = true;
- }
- if (err == false) {
- if (email.indexOf("@") == -1) {
- msg = "Your email is missing a @.";
- err = true;
- }
- }
- if (err == false) {
- if (email.indexOf(".") == -1) {
- msg = "Your email address is missing a period.";
- err = true;
- }
- }
- if (msg != "")
- {var myWindow = window.open("","","width=400,height=400");
- myWindow.document.write(msg);}
- if (msg == "" && err == ""){
- if(getCookie('chips') == null)
- {var expdate = new Date();
- expdate.setTime(expdate.getTime() + (1000 * 60* 60 *24 *365));
- setCookie('chips',username);
- window.open() }
- if((getCookie('chips') != null) && (getCookie('chips') == username))
- {msg = msg + username + "You entered your name already!\n"
- var myWindow = window.open("","","width=400,height=400");
- myWindow.document.write(msg);}
- else
- {var expdate = new Date()
- expdate.setTime(expdate.getTime());
- setCookie('chips',username);
- window.open()}
- return(msg)
- }
- function getCookieVal (offset){
- var cooklen = document.cookie.indexOf (";", offset);
- if (cooklen == -1)
- {cooklen = document.cookie.length;}
- return unescape(document.cookie.substring(offset, cooklen));
- }
- function getCookie (c_name){
- var arg = c_name + "=";
- var argLen = arg.length;
- var cooklen = document.cookie.length;
- var i = 0;
- while (i < cooklen)
- {var j = i + argLen;
- if (document.cookie.substring(i, j) == arg)
- {return getCookieVal(j)}
- if (i == 0)
- {break}
- }
- return null;
- }
- function setCookie(name, value){
- var argv = setCookie.arguments;
- var argc = setCookie.arguments.length;
- var expires = null;
- var path = null;
- var domain = null;
- var secure = null;
- document.cookie = name + "=" + escape(value) +
- ((expires == null) ? "" : ("; expires=" + expires.toGTMString())) +
- ((path == null) ? "" : ("; path=" + path)) +
- ((domain == null) ? "" : ("; domain=" + domain)) +
- ((secure == true) ? "; secure" : "");
- }
- /* function deleteCookie () {
- var expired = new Date();
- expired.setTime (expired.getTime() - 1000000000);
- var cookieValue = getCookie ('chips');
- document.cookie = 'chips' + "=" + cookieValue + ";
- expires=" + expired.toGMTString();
- }
- // Create a new window
- var myWindow = window.open("","","width=400,height=400");
- myWindow.document.write(msg);
- }
</head>
<body>
<form name="myForm">
First Name: <input name="Fname" type="text"><br>
Last Name: <input name="Lname" type="text"><br>
Email:<input name="myEmail" type="text"><br>
<input type="button" value="submit" onclick="validate()">
</form>
</body>
</html>[/HTML]