I have two pages. In one page I am changing the value of a variable called t, in the other I am outputting it. The problem I'm having is in changing its value. Any help will be greatly appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

 <head>

   <title>Untitled Page</title>
   <link rel="stylesheet" type="text/css" href="radio.css"/>

   <script type="text/javascript">


     var t = 12;
     var questionNum= 1;
     function addQuestion()
     {


      var myButton = document.createElement("input");
	  myButton.id = "buttons"+ questionNum;
	  myButton.setAttribute("type", "button");
	  myButton.setAttribute("name", "questionButton");
	  myButton.value = "Create answer options";
	  myButton.style.color = "blue";
	  myButton.onclick = addRadio;
	  document.getElementById("divRadiolist").appendChild(myButton);



	  var paragraph = document.createElement("p");
	  paragraph.id = "paragraph"+ questionNum;
      document.getElementById("divRadiolist").appendChild(paragraph);

      function addRadio()
	  {


               t = 10;


       }

       var myHiddenText = document.createElement("input");
	   myHiddenText.id = "text" + questionNum;
	   myHiddenText.setAttribute("type", "hidden");
	   myHiddenText.setAttribute("name", questionNum + "text");
	   myHiddenText.setAttribute("value", t);
	   document.getElementById("divRadiolist").appendChild(myHiddenText);

       questionNum++;
    }

      function workPlease()
      {

      var myHiddenText = document.createElement("input");
  	  myHiddenText.id = "text" + questionNum;
  	  myHiddenText.setAttribute("type", "hidden");
  	  myHiddenText.setAttribute("name", "questionNum");
  	  myHiddenText.setAttribute("value", questionNum);
	  document.getElementById("divRadiolist").appendChild(myHiddenText);

	  }
  </script>

  </head>

<body>

  <form id="form1" action="testCheck.php" method="post">
  <input type="button" id="btnAddQuestion" value="Create Question" onclick="addQuestion()" />
  <div id="divRadiolist"></div>
 <p><input type="submit" name="submitted" value="Save Test" onclick="workPlease()"/></p>
  </form>

</body>

</html>

Here is where the value of t is output. I want it to give back 10 but it gives back 12.

<?php

     session_start();

     $questionNum = $_POST["questionNum"];
     $_SESSION['questionNum'] = $questionNum;

     $i = 1;
     while($i < $questionNum ){

       $question = "question".$i;
       $_SESSION['question'.$i]=$_POST[$question];


       $answerOptions = "1text";
       $trial = $_POST[$answerOptions];
       echo "This is a trial {$trial}";
       $_SESSION['answerOptions'.$questionNum] =$tial;

       $j = 1;
       while($j < $answerOptions){

       $answerOption = $questionNum."text".$j;
       $_SESSION[$questionNum."text".$j] = $_POST['answerOption'];

       $j++;
       }

       $i++;

     }
?>

Regards,
Towlie.

Really simple error. what was happening was that your variable was never set to 10 because the function was never called.
In your addfunction function change this:

myButton.onclick = addRadio;

to

myButton.onclick = addRadio();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.