Archive | September, 2012

codes

24 Sep

<html>
<head>
<script type=”text/javascript”>
function validateForm()
{

var fname = document.forms[“myform”][“fName”].value;
var lname = document.forms[“myform”][“lName”].value;
var email = document.forms[“myform”][“emailID”].value;
if(fname == “” || fname == null)
{
alert(“First Name cannot be NULL”);

return false;
}
if(lname == “” || lname == null)
{
alert(“Last Name cannot be NULL”);
status = false;

}

var atpos = email.indexOf(“@”);
var dotpost = email.lastIndexOf(“.”);
if(atpos < 1 || dotpos < atpos + 2 || dotpost+2 >= email.length)
{
alert(“Not a valid email address”);
return false;
}

}

</script>
</head>
<body>
<form name = “myform” onsubmit = “return validateForm()” method = “post” >
First Name: <input type = “text” name = “fName”/>
Last Name: <input type = “text” name = “lName”/>
Email ID: <input type = “text” name = “emailID”/>
<input type = “Submit” value = “Submit”/>
</form>
</body>
</html>

 

 

 

<!DOCTYPE html>
<html>
<head>
<script>
var c=0;
var t;
var timer_is_on=0;

function timedCount()
{
document.getElementById(‘txt’).value=c;
c=c+1;
t=setTimeout(function(){timedCount()},1000);
if(c == 41)
{
alert(“Time expired”);
stopCount();
}
}

function doTimer()
{
alert(“reached”);
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(“;”);
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf(“=”));
y=ARRcookies[i].substr(ARRcookies[i].indexOf(“=”)+1);
x=x.replace(/^\s+|\s+$/g,””);
if (x==c_name)
{
return unescape(y);
}
}
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? “” : “; expires=”+exdate.toUTCString());
document.cookie=c_name + “=” + c_value;
}

function checkCookie()
{
var username=getCookie(“username”);
if (username!=null && username!=””)
{
alert(“Welcome again ” + username);
}
else
{
username=prompt(“Please enter your name:”,””);
if (username!=null && username!=””)
{
setCookie(“username”,username,365);
}
}
}
</script>
</head>

<body onload = “doTimer();checkCookie();”>
<form>
First Name: <input type = “text” name = “fName”/>
Last Name: <input type = “text” name = “lName”/>
Email ID: <input type = “text” name = “emailID”/>
<input type = “Submit” value = “Submit”/>
<br/> <br/>
<input type=”text” id=”txt” />
</form>
<p>
Click on the “Start count!” button above to start the timer. The input field will count forever, starting at 0. Click on the “Stop count!” button to stop the counting. Click on the “Start count!” button to start the timer again.
</p>
</body>
</html>