How can I pass selected checkbox values to another servlet (not below one) using jQuery post method?
This is my servlet code for generationg check boxes on the html page I am using json
for(int i=0;i<roles.size();i++){
JSONObject msg = new JSONObject();
msg.put("selector", "#roles");
//<input type=radio name="radio" value="<%=bean.getSno()%>"></td>
msg.put("msg",
"<input type=checkbox id="+'"'+"checkedroles"+'"'+"name="+'"'+"checkedroles"+'"'
+"value="+roles.get(i)+">"+roles.get(i)+"<br>");
messages.put(msg);
}
this is the jquercode
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$(document).ready(function(){
//global vars
var UserName = $("#UserName"); //user name field
var FirstName = $("#FirstName"); //first name
var LastName=$("#LastName");
var StreetAdress=$("#StreetAdress");
var City=$("#City");
var Province=$("#Province");
var Organization=$("#Organization");
var email=$("#email");
var phone=$("phone");
var checkedroles=$("#checkedroles");
var selected = new Array();
function checkCommentsForm(){
return true;
}
$("input:checkbox[name=checkedroles]:checked").each(function() {
selected.push($(this).val());
});
//When form submitted
$("#Reg").submit(function(){
if(checkCommentsForm()){
$.ajax({
type: "post",
url: "loginProcess.jsp",
data: {user : UserName.val(), fname : FirstName.val(),lname : LastName.val()
,stAddress:StreetAdress.val(),city:City.val(),prov:Province.val(),org:Organization.val()
,mail:email.val(),ph:phone.val(),'ch[]':selected},
success: function(data) {
}
});
}
});
});
also pls tell me how to retrieve the array in the servlet