title: Showing value in html textbox from javascript
body: <p>In my code I have three radio buttons and if user selects one and clicks submit button (name="generateQuestion"), it should show some text in the textbox (name="quest") based on user's choice. My problem is, I am getting some value from the javascript but it appears in the html textbox and vanishes immediately. It seems that on clicking submit button the javascript function is called and textbox value is updated but as the page is getting reloaded, the value vanishes and textbox holds it default value again. I need to keep the value in textbox. I have checked the problem with IE, FF and chrome and got same result. Please let me know if I need to add something in the code. Right now I have not written the logic in JS function for user's choice but just need to set the html textbox value from javascript and the value should be retained in textbox after clicking submit button.</p>
  
  <p>Html</p>
  
  <pre><code>        &lt;form id="mathForm" name="mathForm" action="" method="post"&gt;
                          Step 1: Do you want to Add, Substract or Multiply?&lt;br&gt;
                          &lt;input type="radio" id = "add" name="mathQ" value="addition"&gt;Answer a question on Addition&lt;br&gt;
                          &lt;input type="radio" id = "subt" name="mathQ" value="subtraction"&gt;Answer a question on subtraction&lt;br&gt;
                          &lt;input type="radio" id = "mul" name="mathQ" value="multiplication"&gt;Answer a question on multiplication&lt;br&gt;
                          &lt;input type="submit" onclick="setQuestion()" id = "genQues" name="generateQuestion" value="          Step 2:Generate Question Item!          "&gt;&lt;br&gt;&lt;br&gt;
                          Here's your Question:&lt;br&gt;
                          &lt;input type="text" id="quest" name="quest" size="45"&gt;&lt;br&gt;&lt;br&gt;
                          Step 3:Type your answer here:&lt;br&gt;
                          &lt;input type="text" name="answer" size="45"&gt;&lt;br&gt;&lt;br&gt;
                          &lt;input type="submit" name="checkAnswer" value="          Step 4:See if you are right!          "&gt;&lt;br&gt;&lt;br&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>        var radioVal;
  
          function setQuestion()
          {
          var radios = document.getElementsByName('mathQ');
  
          for (var i = 0, length = radios.length; i &lt; length; i++) 
          {
              if (radios[i].checked) 
              {
                  radioVal = radios[i].value;
                  break;
              }
          }
  
          var num1 = (Math.random()*10^17)%19;
          var num2 = (Math.random()*10^17)%19;
  
          var txt = 'some text';
          var tbox = document.getElementById('quest');
          tbox.value = txt;
  
          }
  </code></pre>