So I had been using this generic code to create a URL from the form elements
function submiturl() {
url="Search.do?call=JS";
var elem = document.getElementById('searchInput').elements;
for(var i = 0; i < elem.length; i++) {
url = url + "&" + escape(elem[i].name) + "=" + escape(elem[i].value);
}
url = url.substring(0,(url.length-1));
alert(url);
}
however it does not handle checkboxes properly - I only want to add to the URL if the checkboxes are checked. So if you had this html
<html>
<body>
<form name="searchInput" id ="searchInput">
<input name="first" type="checkbox" value="123"/>One two three
<input name="second" type="checkbox" value="456"/>Four five six
<button type="button" onClick="submiturl();">Submit</button>
</form>
</body>
</html>
it will create the URL using the value for both checkboxes regardless if they were checked or not.
So how can I modify my javascript to check if it is a checkbox and is checked?
thanks!