...

View Full Version : passing javascript variable value to php



Nirbhay
05-21-2009, 12:39 PM
Hi All,

I need to access the javascript varaible value inside php block.
the scenario is that I have a function in javascript
function display()
{
//here I have the start date in start_date varible
//inside same function I have php block
<?
here I need to access the start_date value.
?>
}
can anyone help me ..


thanx in advance

mic2100
05-21-2009, 01:12 PM
how is the `start_date` value assigned in the first place?

would this not be easier to start with that value assigned in PHP then get the PHP to assign to a JS variable.

I say that becuase what u are trying to do isn't possible...

PHP is a server side language, this means that is is executed on the server before any HTML JS or CSS is passed to the browser.

example....


<? $start_date = "1980-12-10"; ?>
function display()
{
//here I have the start date in start_date varible
//inside same function I have php block

var start_date = '<?=$start_date?>' //u will need to convert this into a date object

<?
//u can now use $start_date to access the required value.
?>
}

Nirbhay
05-21-2009, 01:17 PM
thanx for reply but I think you didn't get the question

the problem is that the inside the javascript function display()
I have the start date value now the same value I want to asign to one php variable inside the same function ...

mic2100
05-21-2009, 01:23 PM
the problem is u can't pass a JS variable to PHP without using some kind of AJAX request, as i sed above PHP is server side and is executed before the JS runs.

wen u run a PHP page on a website view the source code, there is no PHP in it and this is because as far as ur browser is concerned its is only receiving HTML, JS and CSS



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum