Passing Javascript variables to PHP

It's easy to get Javascript variable into PHP.

What you have to do is follow below code.


//in script block
var veg = 'Carrot';
//in php block
$veg = "<script type='text/javascript'>document.write(veg);</script>";
echo 'Printed My JS variable into PHP: '.$veg;

Result will be:
Printed My JS variable into PHP: Carrot

Comments

Popular posts from this blog

Send email from xampp localhost

Convert long url to short url using tinyurl api

Modify item price in cart after placing order using sales_quote_add_item