PDA

Click to See Complete Forum and Search --> : PHP & Javascript variables...........


rammy
Jan 4th, 2002, 04:51 AM
Hi,
Is it possible to use Javascript variables in PHP code? I need to be able to assign the values of javascript variables to PHP variables.
I am able to display the values using the alert statement. But how can these values be assigned to PHP variables?

Thanx a lot.

Here's my sample code:



<html>
<head>
<title>Test page</title>
<Script language="javascript">
var a;
var a1 = new Array();

function testfn()
{
var i;
a='abc';
for (i=0;i<=4;i++)
a1[i]=i;
}

</script>
</head>

<body>
<?php
echo "<script language='javascript'>";
echo "testfn();";
echo "alert(a);";
echo "alert(a1[2]);";
echo "</script>";
?>
</body>
</html>




Is it possible for me to assign the values of "a" and the array "a1" to PHP variables?? Thanx again.

CiberTHuG
Jan 4th, 2002, 08:58 AM
I'm not giving the lecture again.

I will sum up to say:

The page will be created by the server-side technology (PHP) before it is sent to the client, where the client-side scripting will be instantiated.

In other words, by the time a JavaScript variable is born, all of the PHP variables have died.

You can "assign" the value of a PHP variable to a JavaScript variable simply because PHP is writing the page, and it can write a JavaScript variable declaration.

progressive
Jan 4th, 2002, 09:55 AM
rammy:

Tell us exactly what you want to achieve and we'll provide a workaround.

As it stands I can't see why you would want to be able to do this!