Forum Moderators: coopster
I have the following call to JScript in my php:
echo "<script type=\"text/javascript\">var eurprice_0" . $cnt . " = $js_property_price;</script>";
The above does not work. However, if I hard-code the price
echo "<script type=\"text/javascript\">var eurprice_0" . $cnt . " = '123456+';</script>";
then the script works and returns the property value in selected currency with or without + sign at the end depending on + sign being passed in the string in the first place.
I have echoed $js_property_price before passing it to JS and I can see that it contains the correct value (i.e. the same value which, when hard-coded, works.)
Any ideas? Or are there any rules I should be aware of?
Thanks
It is a bit frustrating as I neither know PHP nor JS and where some things should work, they don't so I am finding long way around to achieve what I want to do.
For example, in JS the If/else statement did not seem to work and 'else' part got executed every time even the code first went through 'true' part of the statement. I solved this by replacing IF with SWITCH statement. Now, although the JS function works and does what I want it to do, I am wondering WHY the IF statement did not work.
So, for example, in my original code, after the IF statement below was executed, the plusSign variable was always set to " +" (hence gone through 'else' path) even if the nSign is 0:
If (nSign == 0)
{
plusSign = " ";
}
else
{
plusSign = " +";
}
However, when I replaced this with switch statement shown below, then the function did what it supposed to do. So, although problem solved, I am wondering why the IF statement did not work and executed both, true and false (if and else) paths (I verified that both paths are executed by putting alert statements all over the place to see where the code goes and in what order) In other languages that I know the two paths in IF statement are mutually exclusive.
Here is what did work:
switch(nSign)
{
case 0:
plusSign = " ";
break;
case 1:
plusSign = " +";
break;
default:
alert ("Case else: Invalid value in db");
}
Thanks on any clarifications anyone wishes to offer.