#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    New York, NY, USA
    Posts
    253
    Rep Power
    15

    Passing variables from Javascript to PHP


    I want to take some variables that I have in javascript and pass them to PHP as variables. How would I take the variables, userResW and userResH in the following javascript and use them in PHP?:

    Code:
    // SCRIPT LANGUAGE="JavaScript1.2"
    
    	var userResW = null;
    	var userResH = null;
    
    if (screen.height == 768 && screen.width == 1024) {
    	userResW = 1024;
    	userResH = 768;
    } else {	
    	if (screen.height == 600 && screen.width == 800) {
    		userResW = 800;
    		userResH = 600;
    	}
    }
    
    //  End -->
    TIA,
    turannos@mail.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    45
    Rep Power
    14
    best workaround i can think of is something like this.....

    Code:
    <?php
    
                   session_register("screenx");
                   session_register("screeny");
    
    if (!isset($screenx && $screeny) && isset($testx && $testy))
    {
                   $screenx = $testx;
                   $screeny = $testy;
    }
    
    ?>
    
    <html>
    <head>
    
    <script language='javascript'>
    function screensize()
    {
    	testx.value = screen.width;
    	testy.value = screen.height;
    }
    
    </script>
    </head>
    
    <body onload='screensize()'>
    
    <form method='post'>
    <input type='hidden' name='testx'>
    <input type='hidden' name='testy'>
    </form>
    
    </body>
    </html>
    or similar on your first page and then just the php bit on any of the other pages they can link to from there and you should be sorted.
    Afraid it allways takes @ least one page to get php to use jscript values because of the client / server side setup.

    I guess you could do it sneakily with a refresh as well if you wanted........
    Last edited by podulator; October 19th, 2001 at 06:12 PM.

IMN logo majestic logo threadwatch logo seochat tools logo