2011-11-06 26 views
0

任何幫助,這將是偉大的我開車自己瘋了,無法找到任何我可以理解的職位。我正在嘗試創建一個與PHP do循環中的excel相同的表單。 jquery根據主題中選擇的內容動態更改等級。我已經得到了這麼多,但是當第一個主題被選中時,所有10行的等級都會改變。 http://www.gogettersgo-learn.com/ggluser/gglcandidatemulti_form.phpPHP循環與動態選擇框上的jquery

任何幫助將是偉大的!

這裏是我使用的代碼:

表單頁面:

<?PHP include_once dirname(__FILE__).'/gglprotectedmain.php'; ?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>GoGetters Go Learn Candidate Form</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<link rel="stylesheet" type="text/css" href="../css/style.css" media="screen" /> 
<link type="text/css" href="../css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" /> 
<meta name="ROBOTS" content="NOINDEX,NOFOLLOW"> 
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script> 
<script type="text/javascript" src="../js/jquery-ui-1.8.16.custom.min.js"></script> 
<script src="../js/jquery.js" type="text/javascript"></script> 
<script src="../js/custom.js" type="text/javascript"></script> 
<script type="text/javascript"> 

      $(function() { 
       $(".datepicker[]").datepicker({ 
          minDate: new Date(<?php echo $startyear = 1920; ?>, <?php echo $startmonth = 1; ?> - 1, <?php echo $startday = 1; ?>), maxDate: new Date(<?php echo $endyear = 1994; ?>, <?php echo $endmonth = 12; ?> - 1, <?php echo $endday = 31;?>), 
          dateFormat: 'dd/mm/yy', 
          changeMonth: true, 
          changeYear: true, 
          yearRange: '1920:1994' 


          }); 
       filter('.datepicker').removeClass('hasDatepicker').datepicker(); 
      }); 

</script> 
<style type="text/css"> 
      /*demo page css*/ 
      body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;} 
      .demoHeaders { margin-top: 2em; } 
      #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;} 
      #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;} 
      ul#icons {margin: 0; padding: 0;} 
      ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left; list-style: none;} 
      ul#icons span.ui-icon {float: left; margin: 0 4px;} 
     </style>  
</head> 
<body> 
<img src="../images/GoGettersGo-Learn-Logo.png" width="412" height="119"> 
<?PHP require_once ('dbphp.php'); $ID = $_SESSION['email'];?> 

<table width="3000px" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
     <td>   
      <form name="candidateform" method="post" action="../ggluser/gglcandidate_form_code.php"> 
      <input type="hidden" value="<?PHP echo $ID;?>" name="ID">    
      <table border="1" cellspacing="0" cellpadding="5"> 
       <tr> 
        <td valign="top" width="230px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">family name:</font><br> 
        </td> 
        <td valign="top" width="230px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">full names:</font><br> 
        </td> 
        <td valign="top" width="170px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">date of birth:</font><br> 
        </td> 
        <td valign="top" width="110px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">gender:</font><br> 
        </td> 
        <td valign="top" width="470px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">Subject:</font><br>     
        </td> 
        <td valign="top" width="230px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">Grade:</font><br> 
        </td> 
        <td width="100px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">Teacher:</font> 
        </td> 
        <td width="100px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">Special needs candidate:</font> 
        </td> 
        <td width="100px"> 
         <font color="#000000" size="2" face="Arial, Helvetica, sans-serif">Publish results:</font> 
        </td> 
       </tr>       
      </table> 


<?php 

$i = 0; 

    do { 
      echo" <table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">"; 
       echo"<tr>"; 
        echo"<td valign=\"top\" width=\"230px\">"; 
         echo"<input class=\" \" name=\"familyname[]\" id=\"familyname\" type=\"text\" maxlength=\"250\" size=\"30\" />"; 
        echo"</td>"; 
        echo"<td valign=\"top\" width=\"230px\">"; 
        echo"<input name=\"fullname[]\" id=\"fullname\" type=\"text\" maxlength=\"250\" size=\"30\" />"; 
        echo"</td>"; 
        echo"<td valign=\"top\" width=\"170px\">"; 
        echo"<p><input type=\"text\" class=\"datepicker\" id=\"datepicker\" name=\"datepicker[]\"></p>"; 
        echo"</td>"; 
        echo"<td valign=\"top\" width=\"110px\">"; 
         echo"<label>"; 
         echo"<input type=\"radio\" name=\"gender[]\" value=\"male\" id=\"gender_0\">"; 
         echo"m</label>"; 
         echo"<label>"; 
         echo"<input type=\"radio\" name=\"gender[]\" value=\"female\" id=\"gender_1\">"; 
         echo"f</label>"; 
         echo"<br>"; 
        echo"</td>"; 
        echo"<td valign=\"top\" width=\"470px\">"; 

         $subject_title = subject_subject(); 
        echo"<div class=\"subject_title\" id=\"subject_title\">"; 

          echo "<select class=\"s_title\" id=\"s_title\" name=\"subject[]\">"; 
           echo "<option value=\"\"></option>"; 
           foreach($subject_title as $subject_title): 

           $subject_title = $subject_title['subject_title']; 
           echo "<option value=\"$subject_title\">"; 
           echo $subject_title; 
           echo "</option>"; 
           endforeach; 
          echo "</select>"; 
          echo $i; 
         echo"</div>"; 

        echo"</td>"; 
        echo"<td width=\"230px\">"; 
         echo"<div class=\"subject_grade\" id=\"subject_grade\"> "; 
         echo $i; 
         echo "</div>"; 
        echo"</td>"; 
        echo"<td width=\"100px\">"; 
         echo"<input name=\"teacherchk[]\" id=\"teacherchk\" type=\"checkbox\" value=\"yes\"><br>"; 
         echo"<div id=\"teacherd\">"; 
         include_once ('../ggluser/gglteachers_details.php'); 
         echo"</div>"; 
        echo"</td>"; 
        echo"<td width=\"100px\">"; 
         echo"<input name=\"spcchk[]\" id=\"spcchk\" type=\"checkbox\" value=\"yes\"><br>"; 
         echo"<div id=\"spcd\">"; 
         include_once ('../ggluser/gglspecial_details.php'); 
         echo"</div>"; 
        echo"</td>"; 
        echo"<td width=\"100px\">"; 
         echo"<input name=\"pubres[]\" id=\"publres\" type=\"checkbox\" value=\"yes\"><br>"; 
        echo"</td>"; 
       echo"</tr>";       
      echo"</table>"; 

++$i; 
echo $i; 
} while ($i < 10); 

?> 

      <table width="300"> 
       <tr> 
        <td width="50"> 
        <input type="submit" name="subok" value=" submit " /> 
        </td> 
        <td width="50" align="left"> 
        <input name="reset" type="reset" value=" reset " /> 
        </td> 
       </tr> 
      </table> 
      </form> 
     </td> 
    </tr> 
</table> 

</body> 
</html> 

JQUERY PAGE:

$(document).ready(function(){ 
     $('.s_title').change(function(){ 
        $.post(
          '../ggluser/gglpopulate_subjectphp.php', 
          { subject_title:$('.s_title').val()}, 
          function(res){ 
            $('.subject_grade').html(res); 

          } 
          ); 

      }); 

}); 


$(document).ready(function(){ 

     //Hide div w/id extra 
     $(".subject_title").css("display","yes"); 
     // Add onclick handler to checkbox w/id checkme 
     $(".subjectchk").click(function(){ 

     // If checked 
     if ($(".subjectchk").is(":checked")) 
     { 
      //show the hidden div 
      $(".subject_title").show("fast"); 
      $('.subject_grade').html(res); 
     } 
     else 
     {  
      //otherwise, hide it 
      $(".subject_title").hide("fast"); 
      $(".subject_grade").hide("fast"); 
     } 
     }); 
    }); 

PHP函數PAGE:

function subject_subject(){ 
    $con = dbConnect(); 
    $qry = "SELECT * FROM tblgosubjectdetails GROUP BY subject_title"; 
    if(!$result = mysql_query($qry)){ 
     echo mysql_error(); 
     return false; 
    } 
    $result = tablearray($result); 

    mysql_close(); 

    return $result; 

} 

function subject_grade($subject_title){ 
    $con = dbConnect(); 
    $qry = "SELECT * FROM tblgosubjectdetails WHERE subject_title = '$subject_title' GROUP BY subject_grade"; 
    if(!$result = mysql_query($qry)){ 
     echo mysql_error(); 
     return false; 
    } 
    $result = tablearray($result); 

    mysql_close(); 

    return $result; 

} 

在此先感謝! :)

+0

這是很多代碼....提示:不要''回聲'HTML這樣的。這很難調試。 –

+2

這是很多代碼,並且沒有明確的錯誤信息。嘗試減少一點,並更清楚你有什麼具體問題 –

回答

0

對於你提到的問題,你可能想使你的change功能是這樣的

$('.s_title').change(function(){ 
    var $self = $(this); 
    $.post(
      '../ggluser/gglpopulate_subjectphp.php', 
      { subject_title: $self.val() }, 
      function(res){ 
       $self.closest('tr').find('.subject_grade').html(res); 
      } 
    ); 
}); 

當你擁有它,它是匹配與類subject_grade

幾個的所有元素更多建議

  • 我認爲$('.datepicker[]')會給你一個錯誤。您可能需要$('.datepicker')
  • 請確保您不要將同一個id分配給多個HTML元素,而您在do...while循環中似乎經常使用該元素。
  • 請考慮至少把所有的JavaScript代碼放在一個地方,無論是在一個單獨的文件或在您的網頁的底部。
  • 您可以將所有jQuery代碼包裝在一個單獨的$(document).ready(function() { ... })塊中。
+0

非常感謝,我會放棄這一點。 – user1032227

+0

嗨,我仍然不能得到這個工作,當我插入你的代碼等級框不顯示? – user1032227