|
-
Jan 4th, 2002, 05:51 AM
#1
Thread Starter
Hyperactive Member
PHP & Javascript variables...........
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:
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.
-
Jan 4th, 2002, 09:58 AM
#2
Frenzied Member
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.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jan 4th, 2002, 10:55 AM
#3
Hyperactive Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|