passing php variable to javascript and vice versa
i wrote this html form to gather some info...
<html>
<head>
<title> The form </title>
</head>
<body>
<form name="myform" action = "gettodb.php" method = "post" >
Enter Id:<br>
<input type="text" name="id" ><br>
Enter date:<br>
<input type="text" name="date1" ><br>
<select name="col">
<option value ="blue">blue
<option value ="black">black
<option value ="yellow">yellow
</select><br>
<input type = "submit" value="Enter"><br>
</form>
</body>
</html>
in gettodb.php i need to perform some operations on the date1 variable using javascript then pass the processed variable back to php to store it in mysql car table.. here the gettodb.php code..
<html>
<body>
<?
extract( $_POST );
if (!$id || !$date1 || !$col)
{
echo "not entered";
exit;
}
$id=addslashes($id);
$col=addslashes($col);
echo "
<script language = \"JavaScript\">
document.write("in in in");
var date1='$date1'
function convert(date1)
{
var arg = date1.split("-");
var l,n,i,j,k;
var d=parseInt(arg[2]);
var m=parseInt(arg[1]);
var y=parseInt(arg[0]);
var jd=intPart((11*y+3)/30)+354*y+30*m-intPart((m-1)/2)+d+1948440-385;
var aa = jd;
if (jd> 2299160 )
{
l=jd+68569;
n=intPart((4*l)/146097);
l=l-intPart((146097*n+3)/4);
i=intPart((4000*(l+1))/1461001);
l=l-intPart((1461*i)/4)+31;
j=intPart((80*l)/2447);
d=l-intPart((2447*j)/80);
l=intPart(j/11);
m=j+2-12*l;
y=100*(n-49)+i+l;
}
else
{
j=jd+1402;
k=intPart((j-1)/1461);
l=j-1461*k;
n=intPart((l-1)/365)-intPart(l/1461);
i=l-365*n+30;
j=intPart((80*i)/2447);
d=i-intPart((2447*j)/80);
i=intPart(j/11);
m=j+2-12*i;
y=4*k+n+i-4716;
}
arg[2]=d;
arg[1]=m;
arg[0]=y;
document.write(arg.join("-"));
document.write(arg);
}
function intPart(floatNum){
if (floatNum< -0.0000001){
return Math.ceil(floatNum-0.0000001)
}
return Math.floor(floatNum+0.0000001)
}
</script>";
$date1=addslashes($date1);
@ $db=mysql_pconnect("localhost","","");
if(!$db)
{echo "error";
exit;
mysql_select_db("university");
$q="insert into car values ('".$id."','".$col."','".$date1."')";
$r=mysql_query($q);
if ($r)
echo mysql_affected_rows()."car inserted";
?>
</body>
</html>
best regards..
|