Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - how to add an array to a form submit?

I'm trying to add an array to my form submit action. Please note I do not want to use ajax..just a regular submit after adding this "uids" parameter.

$("#new_meeting").live("submit", function(){
  var uids = [];
  $("span.receiver-name").each(function(){
    var uid_name = $(this).attr("id");
    var uid = uid_name.split("--")[0];
    uids.push(uid);
  })
  $("#new_meeting").append("&uids=" + uids);
});

This is not working since on the server side I'm not seeing the uids parameter. There is also another thing I tried looking at other posts on stackoverflow but couldn't get that to work either..here is that..

  var input = $("<input>").attr("type", "hidden").attr("uids", "mydata").val(uids);
  $('#new_meeting').append($(input));

Has anyone done this? Thanks.

like image 409
absolutskyy Avatar asked Oct 08 '22 07:10

absolutskyy


1 Answers

I'll give a shot before markup,

Change this

$("#new_meeting").append("&uids=" + uids);

to

 var input = $("<input>").attr({"type":"hidden","name":"uids"}).val(uids);
 $('#new_meeting').append(input);
like image 176
Jashwant Avatar answered Oct 12 '22 13:10

Jashwant