I need to add a vendor who is able to supply N no of products so on adding details i need to select the multiple products from the dropdowns and store the selected product in database.
I am using post method.
$(document).ready(function(){
$("#submit").click(function(){
var vendor_name = $("#val-username").val();
var vendor_email = $("#val-email").val();
var vendor_phone= $("#val-phoneus").val();
var vendor_address = $("#val-address").val();
var product_ID = $("select").val();
var xyz=[product_ID];
var dataString = 'vendor_name='+ vendor_name + '&vendor_email='+ vendor_email + '&vendor_phone='+ vendor_phone + '&vendor_address='+ vendor_address + '&product_ID[0]=' + xyz[0] +'&product_ID[1]=' + xyz[1];
if(vendor_name==''||vendor_email==''||vendor_phone==''||vendor_address=='')
{
alert("Please Fill All Fields");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
data: dataString,
cache: false,
success: function(result){
if(result) {
alert("Vendor Added Successfull");
window.location.href= "vendor.html";
//window.href.location='localhost/elearning/admin/categories.html';
}
}
});
}
return false;
});
});
$.getJSON(url, function (data) {
$.each(data.records, function (index, value) {
// APPEND OR INSERT DATA TO SELECT DROPDOWN PRODUCT LIST.
$('#val-prod').append('<option value="' + value.product_ID + '">' + value.product_name + '</option>');
;
});
});
</script>
The issue i am facing is as the remaining fields are single insertion i am able to dd it by post method so for selecting multiple products and storing it in database i need to use array.i tried storing PRODUCT ID in array form but it still adds single product.In VAR DATASTRING I AM UNABLE TO PASS ARRAY DATA FOR N PRODUCTS .
I need to pass multiple product Id for a single vendor so as to store in database the products he supplies