SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to pass javascript variable in PHP?

    Hi


    How to pass javascript variable in PHP?

    Any help ?





    <snip>
    Last edited by TechnoBear; Sep 15, 2012 at 04:30. Reason: Please wait 90 days for a real signature

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Yes sure, give us an example of what you want to send.

  3. #3
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way is to:

    HTML Code:
    <script type="text/javascript" charset="utf-8">
    	var myJsVar="<?php echo $myPhpVar; ?>";
    </script>

  4. #4
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's an onclick example:

    PHP Code:
    echo '<input id="server" onclick="window.location.href=\'filename.php?server='.$server.'\'" type="button" name="server" value="Server">'
    That's javascript using a php variable - don't think it can be done the other way round.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  5. #5
    SitePoint Member blogaddition's Avatar
    Join Date
    Sep 2012
    Location
    India
    Posts
    23
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I am understanding your problem but there is no way to pass the javascript variable to php page rather than ajax or window.location method.

    Code:
    <script type="text/javascript">
    function passvariable(var){
    window.location.href= 'filename.php?var='+var;
    }
    </script>
    
    <input type="button" value="submit" onclick="passvariable('<?php echo $phpvariable;?>');"/>


Bookmarks

Posting Permissions

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