1

我正在尝试根据从数据库中检索到的数据来选择 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 Ajax 处理返回的数据

    $('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>
4

1 回答 1

0

-> 你需要列出需要检查的东西。

  • 首先将警报放入您的成功函数并检查它是否成功返回了您想要的数据。

  • 我检查了您的 html 格式。完全错误。Id 是唯一字段,您使用了 2 次。如果付款方式在组中,则两个单选按钮中的名称字段相同,这在您的 html 中有所不同,例如 PaymentMethods1 和 PaymentMethods2。需要纠正这一点。

  • 在 jquery 中, $("input[name='PaymentMethods1']:checked").val();
    我不明白你为什么放这个。它是在获取值,而你没有使用任何变量来获取这个值。

于 2012-08-04T12:15:12.080 回答