Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2009
    Location
    Bangalore
    Posts
    75
    Thanks
    5
    Thanked 0 Times in 0 Posts

    passing javascript variable value to php

    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

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    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....
    Code:
    <? $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.
    ?>
    }

  • #3
    New Coder
    Join Date
    May 2009
    Location
    Bangalore
    Posts
    75
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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 ...

  • #4
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    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

  • Users who have thanked mic2100 for this post:

    Nirbhay (05-25-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •