title: How to retrieve the selected drop down value on the same page using submit button
body: <p>I am working on a form that has 6 chkboxes and depending on the selection of chkboxes (multiple selection allowed) particular divs are getting displayed. And each div contain some questions (In the form of dropdown boxes &amp; these values are given hardcore &amp; not from DB).  For this I used javascript. Everything is going as expected. But now I want to add submit button (on submit result should display on the same page) &amp; on submitting the form I want to display the selected dropdown values. </p>
  
  <p>Please help me out. Thanks in advance...</p>
  
  <p>Here is my tried code -</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;script&gt;
          var showClasses = { };
          function fnchecked(blnchecked,className)
          {
              if(blnchecked)
              {
                  showClasses[className] = true;
              }
              else
              {
                  showClasses[className] = false;
              }
              var ps = document.getElementById("div-block").children;
              var psNumber = ps.length;
              for (var i = 0; i &lt; psNumber; i ++) {
                  var have = hasClasses(ps[i], showClasses);
                  if (have) {
                      ps[i].style.display = "";
                  } else {
                      ps[i].style.display = "none";
                  }
              }
          }
  
          function hasClasses(element)
          {
              var result = false;
              for (var cls in showClasses) {
                  if (showClasses[cls]) {
                      if ((' ' + element.className + ' ').indexOf(' ' + cls + ' ') &gt; -1) {
                          result = true;
                      }
                  }
              }
              return result
          }
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;form method="POST" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
      &lt;div&gt;
          &lt;label&gt;Technologies: &lt;/label&gt;&lt;/br&gt;
          &lt;input type="checkbox" name="technologies[]" onChange="fnchecked(this.checked,'question1');" value="Kingspan Solar" /&gt; Kingspan Solar&lt;/br&gt;
          &lt;input type="checkbox" name="technologies[]" onChange="fnchecked(this.checked,'question2');" value="Solar PVT" /&gt; Solar PVT&lt;/br&gt;
          &lt;input type="checkbox" name="technologies[]" onChange="fnchecked(this.checked,'question3');" value="Insulation" /&gt; Insulation&lt;/br&gt;
          &lt;input type="checkbox" name="technologies[]" onChange="fnchecked(this.checked,'question4');" value="Gas boiler" /&gt; Gas boiler&lt;/br&gt;
          &lt;input type="checkbox" name="technologies[]" onChange="fnchecked(this.checked,'question5');" value="Oil boiler" /&gt; Oil boiler&lt;/br&gt;
          &lt;input type="checkbox" name="technologies[]" onChange="fnchecked(this.checked,'question6');" value="Heat recovery ventilation" /&gt; Heat recovery ventilation&lt;/br&gt;
           &lt;!--&lt;input type="submit" name="formSubmit" value="Get The Info"&gt;--&gt;&lt;/br&gt;
  
         &lt;input type="submit" name="submit" value="Submit"&gt;&lt;/p&gt;
  
          &lt;?php
              if(isset($_POST['submit'])) 
              {
                  $tech = $_POST['technologies'];
                  if(empty($tech)) 
                  {
                    echo("You didn't select any Technologies.");
                  } 
                  else
                  {
                    $N = count($tech);
  
                    echo("You selected $N Technology(s): ");
                    for($i=0; $i &lt; $N; $i++)
                    {
                      echo($tech[$i] . " ");
                    }
                  }
              }
          ?&gt;
  
          &lt;div id="div-block" &gt;
              &lt;p class=" question1 " style="display: none"&gt;
                  How many people live in the house ?
                  &lt;select name="people"&gt;
                      &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                      &lt;option value="people1"&gt;1 to 3 (200 litre system)&lt;/option&gt;
                      &lt;option value="people2"&gt;3 to 4 (250 litre system)&lt;/option&gt;
                      &lt;option value="people3"&gt;4 to 6 (300 litre system)&lt;/option&gt;
                      &lt;option value="people4"&gt;6 to 9 (400 litre system)&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;p class="question1 question2 question3 question4 question5 question6 " style="display: none"&gt;
                  What type of house do you live in?
                  &lt;select name="house_type"&gt;
                      &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                      &lt;option value="house_type1"&gt;Bungalow&lt;/option&gt;
                      &lt;option value="house_type2"&gt;2 story&lt;/option&gt;
                      &lt;option value="house_type3"&gt;Dormer&lt;/option&gt;
                      &lt;option value="house_type4"&gt;3 or 4 story&lt;/option&gt;
                      &lt;option value="house_type5"&gt;Apartment&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;p class="question1 question2  " style="display: none"&gt;
                  Is your house south facing?
                  &lt;select name="house_face"&gt;
                      &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                      &lt;option value="house_face1"&gt;South&lt;/option&gt;
                      &lt;option value="house_face2"&gt;South east or South west&lt;/option&gt;
                      &lt;option value="house_face3"&gt;East or West&lt;/option&gt;
                      &lt;option value="house_face4"&gt;No&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;p class="question1 question2 question3 question4 question5 " style="display: none"&gt;
                  Was it built before 2006?
                  &lt;select name="built"&gt;
                      &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                      &lt;option value="built1"&gt;Yes&lt;/option&gt;
                      &lt;option value="built2"&gt;No&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;p class=" question2 " style="display: none"&gt;
                    How many people live at the house ?
                        &lt;select name="people"&gt;
                            &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                            &lt;option value="people1"&gt;1-2&lt;/option&gt;
                            &lt;option value="people2"&gt;3&lt;/option&gt;
                            &lt;option value="people3"&gt;4&lt;/option&gt;
                            &lt;option value="people4"&gt;4-6&lt;/option&gt;
                            &lt;option value="people4"&gt;6-8&lt;/option&gt;
                        &lt;/select&gt;
                   &lt;/p&gt;
  
              &lt;p class=" question3 " style="display: none"&gt;
                  Is your house detached?
                  &lt;select name="detached"&gt;
                      &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                      &lt;option value="detached1"&gt;Detached&lt;/option&gt;
                      &lt;option value="detached2"&gt;Semi D&lt;/option&gt;
                      &lt;option value="detached3"&gt;Mid Terrace&lt;/option&gt;
                      &lt;option value="detached4"&gt;Apartment&lt;/option&gt;
                  &lt;/select&gt;
  
              &lt;/p&gt;
  
              &lt;p class=" question4 question5 question6 " style="display: none"&gt;
                  How many bedrooms are in the house?
                  &lt;select name="bedroom"&gt;
                      &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                      &lt;option value="bedroom1"&gt;1-2&lt;/option&gt;
                      &lt;option value="bedroom2"&gt;2-3&lt;/option&gt;
                      &lt;option value="bedroom3"&gt;3-4&lt;/option&gt;
                      &lt;option value="bedroom4"&gt;4-5&lt;/option&gt;
                      &lt;option value="bedroom5"&gt;5-8&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;p  class=" question4 question5 " style="display: none"&gt;
                Do you use gas or oil?
                    &lt;select name="gas_oil"&gt;
                        &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                        &lt;option value="gas_oil1"&gt;Gas&lt;/option&gt;
                        &lt;option value="gas_oil2"&gt;Oil&lt;/option&gt;
                    &lt;/select&gt;
               &lt;/p&gt;
               &lt;p  class=" question4 question5 " style="display: none"&gt;
                House you like to upgrade your central heating controls to SEAI standards so you can claim a grant for the works?
                    &lt;select name="upgrade"&gt;
                        &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                        &lt;option value="upgrade1"&gt;Yes&lt;/option&gt;
                        &lt;option value="upgrade2"&gt;No&lt;/option&gt;
                    &lt;/select&gt;
               &lt;/p&gt;
               &lt;p  class=" question6 " style="display: none"&gt;
                Is this a new build or total renovation?
                    &lt;select name="upgrade"&gt;
                        &lt;option value=""&gt;Click &amp; Choose&lt;/option&gt;
                        &lt;option value="upgrade1"&gt;Yes&lt;/option&gt;
                        &lt;option value="upgrade2"&gt;No&lt;/option&gt;
                    &lt;/select&gt;
               &lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>