Page 1 of 1
how to ask for jscript variable?
Posted: Tue Nov 25, 2003 4:37 pm
by lisawebs
how to ask: if (jscript.variable then...)
Posted: Tue Nov 25, 2003 5:06 pm
by infolock
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
differences in syntax
Posted: Wed Nov 26, 2003 12:28 pm
by lisawebs
your code didn't work, but
var variable = '<?php print "$phpvariable"; ?>'
worked fine, why???????
Posted: Wed Nov 26, 2003 12:53 pm
by infolock
it's because i wasn't call it correctly in jscript. the echo/print doesn't matter, it's just how you call it in jscript ( which i'm not very familiar with ) that does.
why this doesn't work?
Posted: Wed Nov 26, 2003 9:01 pm
by lisawebs
the following works fine:
echo("<script>");
echo("alert('hello')");
echo("</script>");
but inserting the following does not
echo(" var a = $variable ");
why??????
Posted: Wed Nov 26, 2003 9:05 pm
by infolock
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." ");
I read it before but (points) are not explained
Posted: Wed Nov 26, 2003 9:57 pm
by lisawebs
I knew that, but nothing say about your (.points.)
what is that? why it works??
it doesn't work either
Posted: Wed Nov 26, 2003 10:03 pm
by lisawebs
no way,
there's something with the command var...
shows an error about "expected (,coma)"
Posted: Wed Nov 26, 2003 10:05 pm
by infolock
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.
Posted: Wed Nov 26, 2003 10:25 pm
by d3ad1ysp0rk
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?
Posted: Thu Nov 27, 2003 2:23 am
by twigletmac
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?
Double quotes work differently to single quotes:
http://php.net/manual/en/language.types.string.php
Mac