Skip to content Skip to sidebar Skip to footer

How To Take A Value From A JavaScript File And Send It To A PHP File?

Can you tell me how to take a value from a JavaScript file and send it to a PHP file? Code: var year = (year != null) ? year : ''.$this->arrToday['year'].''; var month

Solution 1:

You can use ajax to send JS variables to php (look at jQuery), but you can't execute php code through javascript. Another way (if you must use those variable in a new page) is to pass js variables as GET variables something like:

my_window= window.open ('Event.php?year=2010','mywindow1','status=1,width=350,height=150');

and in php:

echo $_GET["year"]; //prints 2010

Solution 2:

var url = "event.php?year="+year+"&month="+month+"&day"+day;

var win1 = window.open(url,"File name","height=150,width=350,fullscreen=0,location=1,menubar=0,resizable=0,scrollbars=1,status=1,toolbar=0,left=0,top=30");

win1.focus();

In event.php file

Use $_GET['day'], $_GET['month'], $_GET['year'] to get the values


Post a Comment for "How To Take A Value From A JavaScript File And Send It To A PHP File?"