Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 24th, 2005, 01:00 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to onmcv
Default 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..


Similar Threads
Thread Thread Starter Forum Replies Last Post
String to attribute and vice versa Pankaj C XSLT 5 February 13th, 2008 06:42 AM
Query to change rows into columns and vice versa miamikk SQL Language 0 November 13th, 2007 06:41 PM
Numbers to words and vice versa? code_lover SQL Language 0 January 7th, 2007 04:50 PM
Word to XML and vice versa using C# asp.net veeruu ASP.NET 1.0 and 1.1 Professional 2 July 21st, 2006 07:41 PM
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.