Question

I have a php variable as below:

$starting_package_wedding = $_GET['starting_package_wedding']; which outputs

string '75001-90000' (length=11)

Now I have a javascript in which I will need the the starting_package_wedding variable,

var starting_package_wedding = <?php echo $starting_package_wedding; ?>;
alert(starting_package_wedding);

But the above alert alerts the value after doing the negative operation, ie it alerts a value of 14999 which is equal to 75001 minus 90000 ! How can I get the string in javascript file ?

Was it helpful?

Solution

Try adding quotes:

var starting_package_wedding = "<?php echo $starting_package_wedding; ?>";

OTHER TIPS

Do the type casting in javascript as above
var name=add the php variable
var starting_package_wedding = Number(name);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top