to pass value from javascript to php which is on same page
Posted: Tue Jun 09, 2009 7:04 am
My code is here...
I want to get value of time variable at <input type="text" name="clock" border="0" style="border:0px" /> syntax without using <input> tag..But using php script ...please help me....
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<script language="Javascript">
setInterval("settime()", 100);
function settime () {
var curtime = new Date();
var curhour = curtime.getHours();
var curmin = curtime.getMinutes();
var cursec = curtime.getSeconds();
var time = "";
if(curhour == 0) curhour = 12;
time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
(curmin < 10 ? "0" : "") + curmin + ":" +
(cursec < 10 ? "0" : "") + cursec + " " +
(curhour > 12 ? "PM" : "AM");
//document.write('<a href="login.php?name='+s+'">another page</a>');
document.date.clock.value = time;
}
</script>
</head>
<body>
<table border="1">
<form name="date" action="login.php" method="post" >
<tr>
<td width="107">Welcome User:</td>
<td width="205"><input type="text" name="name" value="" style="border:0px" /></td>
</tr>
<tr>
<td>Current Date:</td>
<td><?php echo date("l jS \of F Y ");?></td>
</tr>
<tr>
<td>Current Time:</td>
<td>
<input type="text" name="clock" border="0" style="border:0px" />
<?php
//$s=$_GET["time"];
//echo $s;
//?>
</td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="submit" value="Logout" /></td>
</tr>
</form>
</table>
</body>
</html>