Thursday, December 13, 2012

Auto Fill second input box js

Auto Fill second input box Java Scripts 




when you fill first  input box above second one fills automatically by using the Java Scripts bellow

<html>
<head>
<script type="text/javascript">
    function copy_data(val){
     var a = document.getElementById(val.id).value
     document.getElementById("copy_to").value=a
    }

    </script>
</head>
<body>
<input type="text" name ="a" id="copy_from" onkeyup="copy_data(this)"/>
<input type="text" name ="a" id="copy_to"/>
</body>
</html>

Thursday, December 6, 2012

Elapse time, cookies name and last visited, page load time Java Scripts



Elapse time, cookies name and last visited, page load time Java Scripts 


Following piece of java Scripts code will show you cookie name and the date of last visited the site.

<!DOCTYPE html>
<html>
<head>
<script>
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>
<script type = "text/javascript">



var days = 730;
var lastvisit=new Object();
var firstvisitmsg="This is your first visit to this page. Welcome!";
lastvisit.subsequentvisitmsg="Welcome back visitor! Your last visit was on <b>[displaydate]</b>";

lastvisit.getCookie=function(Name){
var re=new RegExp(Name+"=[^;]+", "i");
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1];
return'';
}

lastvisit.setCookie=function(name, value, days){
var expireDate = new Date();

var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days));
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

lastvisit.showmessage = function() {
var wh = new Date();
if (lastvisit.getCookie("visitc") == "") {
lastvisit.setCookie("visitc", wh, days);
document.write(firstvisitmsg);
}

else {
var lv = lastvisit.getCookie("visitc");
var lvp = Date.parse(lv);
var now = new Date();
now.setTime(lvp);
var day = new Array("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat");
var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var dd = now.getDate();
var dy = now.getDay();
dy = day[dy];
var mn = now.getMonth();
mn = month[mn];
yy = now.getFullYear();
var hh = now.getHours();
var ampm = "AM";
if (hh >= 12) {ampm = "PM"}
if (hh >12){hh = hh - 12};
if (hh == 0) {hh = 12}
if (hh < 10) {hh = "0" + hh};
var mins = now.getMinutes();
if (mins < 10) {mins = "0"+ mins}
var secs = now.getSeconds();
if (secs < 10) {secs = "0" + secs}
var dispDate = dy + ", " + mn + " " + dd + ", " + yy + " " + hh + ":" + mins + ":" + secs + " " + ampm
document.write(lastvisit.subsequentvisitmsg.replace("\[displaydate\]", dispDate))
}

lastvisit.setCookie("visitc", wh, days);

}

lastvisit.showmessage();

</script>
</head>
<body onload="checkCookie()">
</body>
</html>

Bellow codes of Java Scripts shows you elapse time stayed in a specific page as countdown timer 

<html>
<head>
<title>load</title>

<Script Language="JavaScript">

var startDate = new Date();
var startTime = startDate.getTime();

function seconds_elapsed ()
{
var date_now = new Date ();
var time_now = date_now.getTime ();
var time_diff = time_now - startTime;
var seconds_elapsed = Math.floor ( time_diff / 1000 );

return ( seconds_elapsed );
}

function time_spent ()
{

var secs = seconds_elapsed ();


var mins = Math.floor ( secs / 60 );
secs -= mins * 60;


var hour = Math.floor ( mins / 60 );
mins -= hour * 60;


document.display.timeElapsed.value = pad ( hour ) + ":" + pad ( mins ) + ":" + pad ( secs );


setTimeout( "time_spent ()", 1000 );
}

function pad ( num )
{
return ( ( num > 9 ) ? num : "0" + num );
}
</Script>
</head>

<body onLoad="time_spent()">

<form name="display">
<input name="timeElapsed" type="text" size=8>
</form>

</body>
</html>

Following codes are really php in which you can find the tame taken to page load. 

<html>
<head>
</head>
<body>
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';
?>
<body>
<html>

Tuesday, December 4, 2012

HTML Save as word doc

HTML Save as word doc

HTML body content could be save as Microsoft word document by using PHP file as bellow including header information to save as word document.

<?php
  
header("Content-type: application/vnd.ms-word");
  
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>

<!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=Windows-1252\">
<title>Saving HTML as a Word Doc</title>
</head>

<body>
<table border=1 align="center">
<tr><td>Name</td><td>Age</td></tr>
<tr><td>Mark Taylor</td><td>34</td></tr>
<tr><td>Oksana dassie</td><td>32</td></tr>
<tr><td>Oksana Babiac</td><td>38</td></tr>
<tr><td>karina kpoor</td><td>22</td></tr>
<tr><td>Alisa diction jonson</td><td>48</td></tr>
</table>
</body>
</html>