javascript create url from form elements handling checkboxes
<p>So I had been using this generic code to create a URL from the form elements</p>

<pre><code>function submiturl() {
    url="Search.do?call=JS"; 
    var elem = document.getElementById('searchInput').elements;
    for(var i = 0; i &lt; elem.length; i++) {
        url = url + "&amp;" + escape(elem[i].name) + "=" + escape(elem[i].value);
    }
    url = url.substring(0,(url.length-1));
   alert(url);
}
</code></pre>

<p>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</p>

<pre><code>&lt;html&gt;
&lt;body&gt;
&lt;form name="searchInput" id ="searchInput"&gt;
    &lt;input name="first" type="checkbox" value="123"/&gt;One two three
    &lt;input name="second" type="checkbox" value="456"/&gt;Four five six
    &lt;button type="button" onClick="submiturl();"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>it will create the URL using the value for both checkboxes regardless if they were checked or not.</p>

<p>So how can I modify my javascript to check if it is a checkbox and is checked?</p>

<p>thanks!</p>
