0

多くのドロップダウン ボックスを持つフォームに取り組んでおり、データベースからドロップダウンの値を取得しています。すべてが完璧に進んでいますが、送信ボタンを 1 つ追加したいと思います。フォームを送信すると、選択したドロップダウン値とその ID を取得したいと考えています。その方法がわかりません。これで私を助けてください。

前もって感謝します。

これが私のコードです-

      <!DOCTYPE html>
      <html>
      <?php
      $db = JFactory::getDBO();



      ?>
      <head>
      <script>
          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 < 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 + ' ') > -1) {
                          result = true;
                      }
                  }
              }
              return result
          }
      </script>
      </head>
      <body>

      <form name="shohide1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <div>
          <label>Technologies: </label></br>
          <input type="checkbox" name="technologies1" onChange="fnchecked(this.checked,'question1');" /> Kingspan Solar</br>
          <input type="checkbox" name="technologies2" onChange="fnchecked(this.checked,'question2');" /> Solar PVT</br>
          <input type="checkbox" name="technologies3" onChange="fnchecked(this.checked,'question3');" /> Insulation</br>
          <input type="checkbox" name="technologies4" onChange="fnchecked(this.checked,'question4');" /> Gas boiler</br>
          <input type="checkbox" name="technologies5" onChange="fnchecked(this.checked,'question5');" /> Oil boiler</br>
          <input type="checkbox" name="technologies6" onChange="fnchecked(this.checked,'question6');" /> Heat recovery ventilation</br>
          <input type="submit" name="formSubmit" value="Get The Info">


          <div id="div-block" >
              <p class=" question1 " style="display: none">

              <?php
              $query = $db->getQuery(true);
              $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=1';
              $db->setQuery((string)$query);
              $results = $db->loadObjectList();
              if ($results)
              {
                  print_r($results['0']->question);
                  echo '<select>';
                  echo '<option value="">Click & Choose</option>';
                  foreach($results as $result) 
                  {
                      echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                  }
                  echo '</select>';
              }
              ?>
              </p>
              <p class="question1 question2 question3 question4 question5 question6 " style="display: none">
              <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=2';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
              </p>
              <p class="question1 question2  " style="display: none">
               <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=3';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
              </p>
              <p class="question1 question2 question3 question4 question5 " style="display: none">
              <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=4';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
              </p>
              <p class=" question2 " style="display: none">
              <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=5';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
             </p>
             <p class=" question3 " style="display: none">
             <?php
              $query = $db->getQuery(true);
              $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=6';
              $db->setQuery((string)$query);
              $results = $db->loadObjectList();
              if ($results)
              {
                  print_r($results['0']->question);
                  echo '<select>';
                  echo '<option value="">Click & Choose</option>';
                  foreach($results as $result) 
                  {
                      echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                  }
                  echo '</select>';
              }
              ?>
             </p>
              <p class=" question3 " style="display: none">
              <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=7';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
              </p>
              <p class=" question4 question5 question6 " style="display: none">
              <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=8';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
              </p>
              <p  class=" question4 question5 " style="display: none">
              <?php
                $query = $db->getQuery(true);
                $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=9';
                $db->setQuery((string)$query);
                $results = $db->loadObjectList();
                if ($results)
                {
                    print_r($results['0']->question);
                    echo '<select>';
                    echo '<option value="">Click & Choose</option>';
                    foreach($results as $result) 
                    {
                        echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                    }
                    echo '</select>';
                }
              ?>
             </p>
             <p  class=" question4 question5 " style="display: none">
             <?php
              $query = $db->getQuery(true);
              $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=10';
              $db->setQuery((string)$query);
              $results = $db->loadObjectList();
              if ($results)
              {
                  print_r($results['0']->question);
                  echo '<select>';
                  echo '<option value="">Click & Choose</option>';
                  foreach($results as $result) 
                  {
                      echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                  }
                  echo '</select>';
              }
             ?>
             </p>
             <p  class=" question6 " style="display: none">
             <?php
              $query = $db->getQuery(true);
              $query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=11';
              $db->setQuery((string)$query);
              $results = $db->loadObjectList();
              if ($results)
              {
                  print_r($results['0']->question);
                  echo '<select>';
                  echo '<option value="">Click & Choose</option>';
                  foreach($results as $result) 
                  {
                      echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
                  }
                  echo '</select>';
              }
              ?>
            </p>
          </div>
      </div>


      </body>
      </html>
4

2 に答える 2

0

隠し型を使用して値を取得できます。

理解を深めるために、隠しタイプを 1 つと新しいボタンを 1 つ追加しました。onselect ドロップダウン イベントで値を確認できます。これはあなたにとって少し役立つかもしれません:

<script>
function setSelectedValue() {

    var objSelect = document.getElementById("demo_onselect").value;
    //alert(objSelect); //your selected value
     document.getElementById('newbutton').value = objSelect; //assign your selected value to new button
      document.getElementById('hiddenfield').value = objSelect; //assign your selected value to new button
     var hiddenid = document.getElementById('newbutton').value;
      var newbtnval = document.getElementById('newbutton').value;
     alert("hidden field value is: "+hiddenid);
      alert("new button  value is: "+newbtnval);

}



</script>
<select style="width: 280px" id="demo_onselect" name="demo_onselect" onchange="setSelectedValue();">
  <option selected="">Please Select</option>
  <option>1</option>
  <option>2</option>
  <option>3</option>

</select>
<input type="hidden" id="hiddenfield" name="hiddenfield" value="" />
<input type="button" id="newbutton" name="newbutton" value="" />

ライブデモはこちら:>>

于 2013-05-09T08:50:29.157 に答える
0

これを試して

id="最初" を選択

option onclick="getValue('.$result->answer.')">

関数 getValue(val){

$('#first').attr("name","val");

}

于 2013-05-09T08:38:40.880 に答える