how to ask for jscript variable?
Moderator: General Moderators
how to ask for jscript variable?
how to ask: if (jscript.variable then...)
couldn't you just set the variable as a PHP variable?
ie, couldn't you just do this :
script language="JavaScript">
<!---
var currLoc = <?php echo $my_var; ?>
....
!-->
and just call it from within php?
like $my_var = 'something';
that way, you are controlling what that variable is in php, instead of trying to do it in jscript..
this is untested of course, but I'm almost sure it would work
edit : of course you would want to set that variable to a value BEFORE you call it in javascript...
so, you'd have
<?php
$my_var='something';
...
?>
<!---
var currLoc = <?php echo $my_var; ?>
....
!-->
all in one file...hope that helps
ie, couldn't you just do this :
script language="JavaScript">
<!---
var currLoc = <?php echo $my_var; ?>
....
!-->
and just call it from within php?
like $my_var = 'something';
that way, you are controlling what that variable is in php, instead of trying to do it in jscript..
this is untested of course, but I'm almost sure it would work
edit : of course you would want to set that variable to a value BEFORE you call it in javascript...
so, you'd have
<?php
$my_var='something';
...
?>
<!---
var currLoc = <?php echo $my_var; ?>
....
!-->
all in one file...hope that helps
differences in syntax
your code didn't work, but
var variable = '<?php print "$phpvariable"; ?>'
worked fine, why???????
var variable = '<?php print "$phpvariable"; ?>'
worked fine, why???????
why this doesn't work?
the following works fine:
echo("<script>");
echo("alert('hello')");
echo("</script>");
but inserting the following does not
echo(" var a = $variable ");
why??????
echo("<script>");
echo("alert('hello')");
echo("</script>");
but inserting the following does not
echo(" var a = $variable ");
why??????
a very nice documentation on proper use of echo is found here : http://www.php.net/echo
if you are just trying to echo out $variable, just use this :
echo (" var a = ".$variable." ");
if you are just trying to echo out $variable, just use this :
echo (" var a = ".$variable." ");
I read it before but (points) are not explained
I knew that, but nothing say about your (.points.)
what is that? why it works??
what is that? why it works??
it doesn't work either
no way,
there's something with the command var...
shows an error about "expected (,coma)"
there's something with the command var...
shows an error about "expected (,coma)"
because it exit's the echo statment, and adds the variable as a result.
take this for example :
if i do this :
$har = 'blah';
echo '$har';
then the word $har is going to show up on my screen, not blah.
however, if i do this :
$har = 'blah';
echo $har;
then the word blah appears on my screen...
so, you have to use that same reasoning when working with strings and variables inside the same echo statement.
so take this for example.
say we have a var named $word that is equal to 'world'.
so :
$word = 'world';
if we try to echo it like this :
echo 'hello $word!';
we are gonna get
hello $word! as a result.
isntead, we have to exit the string to add the variable to the string, like so :
$word = 'world';
echo 'Hello '.$word.'!';
which will produce :
Hello world!
again, view the php manual on more [php_man]echo[php_man] related commands.
take this for example :
if i do this :
$har = 'blah';
echo '$har';
then the word $har is going to show up on my screen, not blah.
however, if i do this :
$har = 'blah';
echo $har;
then the word blah appears on my screen...
so, you have to use that same reasoning when working with strings and variables inside the same echo statement.
so take this for example.
say we have a var named $word that is equal to 'world'.
so :
$word = 'world';
if we try to echo it like this :
echo 'hello $word!';
we are gonna get
hello $word! as a result.
isntead, we have to exit the string to add the variable to the string, like so :
$word = 'world';
echo 'Hello '.$word.'!';
which will produce :
Hello world!
again, view the php manual on more [php_man]echo[php_man] related commands.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Double quotes work differently to single quotes:LiLpunkSkateR wrote:i used to just write
$foo = "the";
echo "$foo dog jumped over $foo brown log";
and it would print fine.. is there a setting that allows this or something?
http://php.net/manual/en/language.types.string.php
Mac