Pregunta

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 ?

¿Fue útil?

Solución

Try adding quotes:

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

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top