2012-08-03 65 views
1

我試圖選擇無線電,複選框和下拉取決於數據庫檢索的數據。到目前爲止,我只嘗試了單選按鈕,但沒有取得任何成功,這是我的。Jquery ajax根據數據庫檢索的數據選擇Radio,複選框和下拉菜單?

edit_cc_form.php

<?php 

include("../MySqlConnection.php"); 


     if(isset($_GET['edit'])) 

     { 

      $id = $_GET['edit']; 

      $query = "SELECT DesiredEffectiveDate, 
          NameofAssociation, 
          DBA, 
          TaxID, 
          StreetAddress, 
          City, 
          State, 
          Zip, 
          AssociationContactName,  
          Telephone,  
          Email,  
          CurrentEligibleMembers,  
          PaymentMethods,  
          LifeLockBasic,  
          LifeLockCommandCenter,  
          LifeLockUltimate, 
          EsignatureTitle, 
          Esignature,  
          DateSigned,  
          WritingProducer, 
          WritingProducerCode 
          FROM Association_Enrollment WHERE id = '$id'"; 

      $result = mysql_query($query); 

      $row = mysql_fetch_row($result); 

      $DesiredEffectiveDate = $row[0]; 

      $NameofAssociation = $row[1]; 

      $DBA = $row[2]; 

      $TaxID = $row[3]; 

      $StreetAddress = $row[4]; 

      $City = $row[5]; 

      $State = $row[6]; 

      $Zip = $row[7]; 

      $AssociationContactName = $row[8]; 

      $Telephone = $row[9]; 

      $Email = $row[10]; 

      $CurrentEligibleMembers = $row[11]; 

      $PaymentMethods = $row[12]; 

      $LifeLockBasic = $row[13]; 

      $LifeLockCommandCenter = $row[14]; 

      $LifeLockUltimate = $row[15]; 

      $EsignatureTitle = $row[16]; 

      $Esignature = $row[17]; 

      $DateSigned = $row[18]; 


      $WritingProducer = $row[19]; 

      $WritingProducerCode = $row[20]; 


      $full = $DesiredEffectiveDate.":".$NameofAssociation.":".$DBA.":".$TaxID.":".$StreetAddress.":".$City.":".$State.":".$Zip.":".$AssociationContactName.":".$Telephone.":".$Email.":".$CurrentEligibleMembers.":".$PaymentMethods.":".$LifeLockBasic.":".$LifeLockCommandCenter.":".$LifeLockUltimate.":".$EsignatureTitle.":".$Esignature.":".$DateSigned.":".$WritingProducer.":".$WritingProducerCode.":".$id; 

      echo $full; 

     } 

?>

jQuery的阿賈克斯,處理返回的數據

$('a.edit_cc_form').click(function(){ 


           $.ajax({ 

            type: 'get', 

            url: 'cc_form/edit_cc_form.php', 

            data: 'ajax=1&edit=' + $(this).attr('id'), 

            success: function(data){ 

              var temp = data.split(':'); 

              $('#DesiredEffectiveDate').val(temp[0]); 

              $('#NameofAssociation').val(temp[1]); 

              $('#DBA').val(temp[2]); 

              $('#TaxID').val(temp[3]); 

              $('#StreetAddress').val(temp[4]); 

              $('#City').val(temp[5]); 

              $('#State').val(temp[6]); 

              $('#Zip').val(temp[7]); 

              $('#AssociationContactName').val(temp[8]); 

              $('#Telephone').val(temp[9]); 

              $('#Email').val(temp[10]); 

              $('#CurrentEligibleMembers').val(temp[11]); 



              if(temp[12] == 'Deduction handled by Association') 
               { 

                $("input[name='PaymentMethods1']:checked").val(); 

               } 


              if(temp[12] == 'Direct Bill Members with Credit Card') 
               { 

                $("input[name='PaymentMethods2']:checked").val(); 

               } 


              $('#LifeLockBasic').val(temp[13]); 

              $('#LifeLockCommandCenter').val(temp[14]); 

              $('#LifeLockUltimate').val(temp[15]); 

              $('#EsignatureTitle').val(temp[16]); 

              $('#Esignature').val(temp[17]); 

              $('#DateSigned').val(temp[18]); 

              $('#WritingProducer').val(temp[19]); 

              $('#WritingProducerCode').val(temp[20]); 

              $('#update_cc').val(temp[21]); 

            } 

           }); 


        $("#cc_form").show(); 

        $("#user_list_cc").hide(); 


     }); // edit CC forms end 

部分,我想根據選擇的形式解析結果後返回存儲在temp [12]上的數據。任何想法如何做到這一點,任何幫助真的很感激。

<td class="section-sub-head"> 
                <label>Payment Methods:</label> 
                <br /><br /> 

                <input type="radio" name="PaymentMethods1" id="PaymentMethods" value="Deduction handled by Association" style="width:20px !important;" class="required"/> Deduction handled by Association 

            <br /> <br />  
               <input type="radio" name="PaymentMethods2" id="PaymentMethods" value="Direct Bill Members with Credit Card" style="width:20px !important;" class="required" /> Direct Bill Members with Credit Card  
                <br /> 
                 <label for="PaymentMethods" class="error" generated="true"></label> 
                 <br /> 
               </td> 

回答

0

- >您需要列出需要檢查的事物。

  • 首先把警報放在你的成功函數中,然後檢查它是否成功返回你想要的數據。

  • 我檢查了你的html格式。它是完全錯誤的.Id是獨特的字段,你使用了2次。如果付款方式在組中,那麼在兩個單選按鈕中的名稱字段是相同的,這是不同的在你的html像PaymentMethods1和PaymentMethods2.need來糾正這一點。在$ jQuery中,$(「input [name ='PaymentMethods1']:checked」)。val();
    我不明白你爲什麼把this.it取值,並且你沒有采取任何變量來取這個值。

+0

我想我弄清楚我的代碼出了什麼問題,謝謝你的幫助! – user1575251 2012-08-08 20:25:45

相關問題