user1532468
user1532468

Reputation: 1753

jquery select change event not posting form data

I am using a jquery change event to populate a dropdown menu when a user selects the correct company. In other words, it populates the second menu with data. Although this is working correctly, when I post the form and capture the data using serialize, there is no company or address details in the post. Just the option value. In this case 'address'. How can I code so that I can gather the data that is posted using this method. Thanks

jquery code

$(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 code

      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>';

Upvotes: 0

Views: 333

Answers (1)

MrCode
MrCode

Reputation: 64526

Here you are hard coding the option value to address for every iteration of the loop:

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

That means whichever address is selected, the server side will only ever see "address". Instead you should insert the address ID into the value.

echo '<option value="' . (int)$row_rs_select_address2['address_id'] . '">'.$address.'</option>';
// assuming the ID is in $row_rs_select_address2['address_id']

Upvotes: 4

Related Questions