Reputation: 21
I have a form that contain a multiple checkbox i want to insert the values of checkbox into the url like this
var a=encodeURIComponent(document.getElementById("idofcheckbox").value)
xmlhttp.open("GET","InsertPHPData.php?q="+a+,true); xmlhttp.send();
Choix1 Upvotes: 0
Views: 1292
Reputation: 2561
Try this:
var x = document.getElementsByTagName("input");
var params = [];
for (var i = 0; i < x.length; i++) {
if (x[i].type === "checkbox") //&& x[i].checked === true
params.push(x[i].name + "+" + x[i].value);
}
var url = "InsertPHPData.php";
url += "?" + encodeURI(params.join(","));
alert(url)
Working fiddle. Please modify accordingly :)
Upvotes: 2