0

当用户选择正确的公司时,我正在使用 jquery 更改事件来填充下拉菜单。换句话说,它用数据填充第二个菜单。虽然这工作正常,但当我发布表单并使用序列化捕获数据时,帖子中没有公司或地址详细信息。只是期权价值。在这种情况下,“地址”。我如何编码,以便我可以收集使用此方法发布的数据。谢谢

jQuery代码

$(function() {

        $("#BA_customer").live('change', function() { 
            if($(this).val()!="")
            $.get("/domain/admin/getDept.php?BA_customer=" + $(this).val(), function(data) {
            $("#BA_dept").html(data).show(); 
            });
            $.get("/domain/admin/getOptions.php?BA_customer=" + $(this).val(), function(data) {
            $("#BA_address").html(data).show(); 
            });

        }); 
          }); 


$(function(){         
        $("#BA_boxform").submit(function(){

         var formdata = $('#BA_boxform').serialize();
         //alert(formdata);
         $.ajax({
           type: "POST",
           url: "/domain/admin/requests/boxes/boxesadd.php",
           data: formdata,
           dataType: 'json',
           success: function(msg){
               //$("#confirm_department").hide();

               /*
               var $dialog = $('<div id="dialog"></div>')
               .html('Your intake was successfully submitted and will be viewable in the reporting area.<br /><br />Thank you.');
               $dialog.dialog({
               autoOpen: true,
               modal: true,
               title: 'Box intake submission successfull',
               width: 400,
               height: 200,
               draggable: false,
               resizable: false,
               buttons: {
               Close: function() {
               $( this ).dialog( "close" );
               }
               }
               });
               */
               //alert('You have succesfully submitted your ' + msg.company + ' report. Thank you.');
               //console.log(msg);
               //$("#BA_addbox").html("You may now close this window.");

               //$("#formImage .col_1 li").show();
               $("#BA_boxform").get(0).reset();
               $("#boxaddform").hide();
          }
       });
         return false;
     });
});

// End function to submit box intake form

getOptions.php 代码

      echo '<label for="address">Address:</label>'.'<br />'.'<select name="customeraddress">';
      echo '<option value="">Select delivery address</option>';
      while ($row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2))
      {
      $address=$row_rs_select_address2['address1_com']. "".
      $row_rs_select_address2['address2_com']. "".
      $row_rs_select_address2['address3_com']. " ".
      $row_rs_select_address2['town_com']. " ".
      $row_rs_select_address2['postcode_com'];
      echo '<option value="address">'.$address.'</option>';
      }
      echo '</select>';
4

1 回答 1

4

在这里,您将选项值硬编码address为循环的每次迭代:

echo '<option value="address">'.$address.'</option>';

这意味着无论选择哪个地址,服务器端都只会看到“地址”。相反,您应该将地址 ID 插入值中。

echo '<option value="' . (int)$row_rs_select_address2['address_id'] . '">'.$address.'</option>';
// assuming the ID is in $row_rs_select_address2['address_id']
于 2013-06-25T16:52:45.440 回答