Results 1 to 2 of 2

Thread: JavaScript value to PHP Array?

  1. #1
    Join Date
    Feb 2009

    JavaScript value to PHP Array?


    Can anyone help me pass a JavaScript value to PHP.

    It's based around jQuizMe script. I'm trying to pass the JavaScript value to a new page, so I can do what I like with it in PHP.

    quizInfo.numOfRight is the JavaScript array of the value of the persons final quiz score is stored in.

    PHP Code:
    if( quizInfo.hasQuit ){

    ScoreForPHP =  quizInfo.numOfRight;


    I'm thinking that perhaps we will need to redirect the person to another page when quizInfo.hasQuit is ran, then storing the JavaScript value into a PHP Array.

    But rather confused about how I go about it.


  2. #2
    Join Date
    Sep 2008
    Akron, OH
    One way of doing this is sending the variable through the URL and picking it up with a PHP request. Here's a basic example:

    <!doctype html>
    		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    		<meta name="language" content="en" />  
    		<script type="text/javascript">
    				function passVariable(){
    					// set your variable
    					var x = '123';
    					// get the current url and append your variable
    					var url = document.location.href + '?x=' + x;
    					// to prevent looping, check to make sure your current url contains a common string
    					var exists = document.location.href.indexOf('?x=');
    					if(exists < 0){
    						// redirect passing your variable in
    						window.location = url;
    	<body onload="passVariable()">
    		<?php echo $_REQUEST['x']; ?>
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

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
HTML5 Development Center