0

addQuestions.php には、それぞれ値が 1 ~ 4 の単一、複数、マトリックス、および真偽の種類の質問の 4 つのオプションがあります。条件 id ==1 の場合、singleQuestion.php などのファイルが含まれます。ここで発生した問題は、singleQuestion.php にラジオ ボタンの 4 つのオプションがあることです。そのため、ajax がそのファイルを要求すると、singleQuestion.php のすべてのコンテンツが表示されるため、addQuestions.php にあるフォームを送信するたびに、singleQuestion.php 入力の値を取得していません。以下は私のコードです:- addQuestions.php

<form action="insertQuestion.php" method="post">
   <select name="selectQuestionType" class="questionInput" onchange='showUser(this.value)' id="selectQuestionType">
           <option value="0" selected>Select Question Type</option>
           <option value="1">Single Choice </option>
           <option value="2">Multiple Choice Question</option>
           <option value="3">Fill in the Blanks</option>
           <option value="4">True False</option>
           <option value="5">Match Matrix</option>
      </select>
<input type="submit" class="button add" value="Save" style="width:auto;" id="addSave" name="myAddSave">
                  <input type="submit" class="button add" value="Save & Next" style="width:auto;" id="saveNext" name="myNextSave">
 <script type="text/javascript">

`

        function showUser(str)
        {
                if (str=="")
                       {
                        document.getElementById("txtHint").innerHTML="";
                          return;
                        } 
                if (window.XMLHttpRequest)
                    {   // code for IE7+, Firefox, Chrome, Opera, Safari
                          xmlhttp=new XMLHttpRequest();
                    }
                  else
                    {   // code for IE6, IE5
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                       xmlhttp.onreadystatechange=function()
                    {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                      {
                      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                      }
                    }
                        xmlhttp.open("GET","getQuestions.php?q="+str,false);
                        xmlhttp.send();
                    }        



                    </script>
                    <div id="txtHint"><b>Question Mode will Be displayed here!.</b></div>
                    <input type="submit" class="button add" value="Save" style="width:auto;" id="addSave" name="myAddSave">
                    <input type="submit" class="button add" value="Save & Next" style="width:auto;" id="saveNext" name="myNextSave">
                    `

getQuestions.php

    <?php

 $q=$_GET["q"];
if($q==1)
{
    include 'singleQuestion.php';
}
else if($q == 2)
   {

       include 'multipleQuestion.php';
   }

else if($q == 3)
  {
    include 'fillQuestion.php';
  }   
else if($q == 4)
 {
    include 'trueQuestion.php';
 }
else if($q == 5)
 {
     include 'matchQuestion.php';
 }
 else 
  {
        echo 'You Have Not Selected Any Question Type Yet!';
  }


?>

singleQuestion.php 内

<style type="text/css"> .javascript { display: none; } </style>
<?php
    echo $Answer1 = $_POST['Answer1'];
         echo $Answer2 = $_POST['Answer2'];
?>
<br>
<div class="singleContainer">

<div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">A</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide1" class="jdText">
    <input type="text" name="Answer1" style="width:600px;padding:7px;"  >
</div> </div>

    <br><br><div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">B</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1" ></span>
</div>
<div id="Hide2" class="jdText">
    <input type="text" name="Answer2" style="width:600px;padding:7px;" value="joydseep" >
</div> </div>

    <br><br><div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">C</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide3" class="jdText">
    <input type="text" name="Answer3" style="width:600px;padding:7px;" >
</div> </div>

    <br><br><div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">D</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide4" class="jdText">
    <input type="text" name="Answer4" style="width:600px;padding:7px;"  >
</div> </div>
<div id='TextBoxesGroup'>
    <div id="TextBoxDiv1">
        <label style="color:#F1F1F1;">Textbox #1 : </label>
    </div>
</div>
<br>
<div class="javascript">your script data to be executed. </div> 
<input type="submit" name="jdb">
</form>

</div>

insertQuestion.php

<?php
echo $Answer1 = $_POST['Answer1'];
         echo $Answer2 = $_POST['Answer2'];
?>

上記は私のコードです。私は ajax の初心者なので、ajax についてあまり知りません。

4

1 に答える 1

1

singleQuestion.phpあなたに従って変更します

<?php
if(isset($_POST['jdb'])){
    echo $Answer1 = $_POST['Answer1'];
         echo $Answer2 = $_POST['Answer2'];
}
else{
?>
<br>
<div class="singleContainer">
<form name="form1" action="" method="post">
<div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">A</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide1" class="jdText">
    <input type="text" name="Answer1" style="width:600px;padding:7px;"  >
</div> </div>

<br><br><div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">B</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1" ></span>
</div>
<div id="Hide2" class="jdText">
    <input type="text" name="Answer2" style="width:600px;padding:7px;" value="joydseep" >
</div> </div>

    <br><br><div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">C</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide3" class="jdText">
    <input type="text" name="Answer3" style="width:600px;padding:7px;" >
</div> </div>

    <br><br><div class="jdRadio">
<div class="jdRaOne">
    <span class="Answer">D</span><br><br>
    <span class="jdAnswer"><input type="radio" name="A1"></span>
</div>
<div id="Hide4" class="jdText">
    <input type="text" name="Answer4" style="width:600px;padding:7px;"  >
</div> </div>
<div id='TextBoxesGroup'>
    <div id="TextBoxDiv1">
        <label style="color:#F1F1F1;">Textbox #1 : </label>
    </div>
</div>
<br>
<div class="javascript">your script data to be executed. </div> 
<input type="submit" name="jdb">
</form>
<?php }?>

あなたのコードではフォーム開始タグを見逃していました

于 2013-04-20T11:04:53.610 に答える