2013-04-20 85 views
0

我有四個選項,分別是addQuestions.php中的單個,多個,矩陣和true值。現在我通過使用Ajax使用get方法請求一個頁面,並在該請求的頁面我已經給出了一個條件,如果id == 1,那麼它將包括一個文件是singleQuestion.php等等。現在的問題已經出現在singleQuestion.php中的單選按鈕有四個選項。所以,當ajax請求文件,然後它顯示singleQuestion.php的所有內容,所以無論何時我提交一個在addQuestions.php中的表單,然後它不檢索singleQuestion.php輸入的值。下面是我的代碼: - addQuestions.php當從ajax請求一個頁面並提交請求頁面的表單時,什麼都不顯示['Solved']

<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,這就是爲什麼我得到stucked.Any幫助將不勝感激多

+0

''你都張貼有輸入RADIL – 2013-04-20 10:09:30

+0

沒有價值,我建議嘗試jQuery的我nstead的飛機javascript – underscore 2013-04-20 10:10:07

+0

我想發佈的文本框的答案是答案6 – user2296650 2013-04-20 10:12:25

回答

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 }?> 
在你的代碼

你錯過形式開始標記

+0

在上面的代碼中,它是沒有用的:( - > if(isset($ _ POST ['jdb'])){$ echo1 = $ _POST ['回答1']; echo $ Answer2 = $ _POST ['Answer2']; }我已經添加它只是爲了檢查它是否顯示值 – user2296650 2013-04-20 11:12:26

+0

然後,您的表單的起始標記在哪裏? – 2013-04-20 11:13:23

+0

它是在addQuestion .php,我還沒有完全寫出我的代碼,它包含了一些400行。你可以假設它從選擇標籤 – user2296650 2013-04-20 11:14:25