Re: Assignment of variables across PHP and JavaScript
| From: | Michael Cartmel | Date: | Fri, 25 Aug 2000 06:59:26 +0000 |
| Subject: | Re: Assignment of variables across PHP and JavaScript | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-13608@lists.php.net to get a copy of this message | ||
Don't get Javascript and PHP confused. Remember that once the page gets to
the browser, all the PHP code has been processed and you are just left with
html/javascript.
If you want to assign PHP values to javascript variables then you should do
something like this:
<script language = "javascript">
<?
$variable = "hi";
printf("var someVar = '%s'", $variable);
?>
</script>
That way, when the page is loaded on the browser the code will look like
this:
<script language = "javascript">
var someVar = 'hi';
</script>
-mic
----- Original Message -----
From: "Ramender Kishore" <romi@accord-soft.com>
To: "PHP Mail List" <php-general@lists.php.net>
Sent: Friday, August 25, 2000 4:51 PM
Subject: [PHP] Assignment of variables across PHP and JavaScript
How can we call a javascript function from within a PHP code block?
javascript:somefunction(php_vars); gives the syntax errors.
"javascript:somefunction(php_vars)"; (enclosing in a pair of quotes) doesn't
give the syntax error but does nothing ... doesn't call the function.
Cannot call the function outside the PHP code block as I am doing something
like,
for($i = 0; $i < $tot_num; $i++)
{
javascript:somefunction(php_vars);
}
actually I want to pass a double dimensional character array into the
javascript function and yesterday itself, I found out that the method to
pass PHP variables into JavaScript is via functions as nothing else was
working ... for single dimension variables as well.
like,
<script language = "javascript">
var someVar = <? echo "$anotherVar"; ?>
</script>
was not working at all.
with the help of functions at least I am able to send across the integers
and strings (single dimension arrays) but now am stuck up with the sending
of double dimensional arrays (array of strings) as the following code which
is for passing strings doesn't work the same way for array of strings as
well:
<script language = "javascript">
function somefunc(aString)
{
alert(aString);
}
</script>
<!-- HTML code block -->
javascript:somefunc(<? echo "$PHP_String"; ?>);
<?php
*** code ***
?>
Do I make sense or have I confused you guys like I am right now?
-Ramender Kishore