The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 10 of 10

Thread: Passing Values from Javascript to PHP

  1. #1

    Passing Values from Javascript to PHP

    I wasn't sure which forum to post this in, but considering it will be ending in PHP I came to server-side.

    What I am trying to do is figure out the local user's time on their machine using javascript, send the time to PHP, and display different stylesheet values depending on what time it is. Sort of like time sensitive CSS.

    I can find the date, time and year easily using javascript, the problem I'm having is sending whatever the value of the date, hour, month, etc. to PHP to figure out which stylesheet to show.

    Any pointers?

  2. #2
    Look into Ajax

  3. #3
    Quote Originally Posted by kortexvfd View Post
    Look into Ajax
    Could you point me to a few related tutorials?

  4. #4
    Normally this place is pretty good:
    http://ajaxian.com/

  5. #5
    lol is there a place I could go and learn what I must without having to email somebody about attending private meetings?

  6. #6
    If you wait a few seconds ill post the code

  7. #7
    Ok, my AJAX code is probs too complex for this, but I started from here: http://www.kirupa.com/developer/php/ajax_intro.htm
    its pretty simple to understand

  8. #8
    http://fr.php.net/manual/en/faq.html.php

    Code:
    <?php
    if (isset($_GET['width']) AND isset($_GET['height'])) {
      // output the geometry variables
      echo "Screen width is: ". $_GET['width'] ."<br />\n";
      echo "Screen height is: ". $_GET['height'] ."<br />\n";
    } else {
      // pass the geometry variables
      // (preserve the original query string
      //  -- post variables will need to handled differently)
    
      echo "<script language='javascript'>\n";
      echo "  location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
               . "&width=\" + screen.width + \"&height=\" + screen.height;\n";
      echo "</script>\n";
      exit();
    }
    ?>
    using HttpRequest:

    Code:
    <script type="text/javascript">
    <!--
    
    function xmlreq(){
      if(window.XMLHttpRequest){
       req = new XMLHttpRequest();
      }else if(window.ActiveXObject){
       req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      return(req);
    }
    function sendPhp(url){
      var req = xmlreq();
      req.onreadystatechange = stateHandler;
      req.open("GET", url, true);
      req.send(null);
    }
    
    sendPhp("updatedatabase.php?username=blah&displayname=whatever");
    //-->
    </script>

  9. #9
    mlk I have no idea what that is for. It looks like some kind of pop up system but I wouldn't know.

    Ok so, after reading this tutorial, I've come to the conclusion I am probably looking at some kind of window.onload function on my ajax.html page, considering I need the date/time to determine which style sheet to use (or style sheet changes to make).

    What I want to know, is should I utilize the JavaScript to find out the date/time on the (in this case) ajax2.php page or leave it in the JavaScript connected to the ajax.html page?

    I think I understand this in theory, I am just confused as to where to run things.
    Last edited by FrankieB; February 16th, 2007 at 03:17 AM.

  10. #10
    Anyone?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012