jquery选择不过帐表单数据的更改事件



当用户选择正确的公司时,我使用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>';

在这里,您将为循环的每次迭代将选项值硬编码为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']

最新更新