Passing parameters to a form, via JavaScript
<p>I have a form which passes a number of parameters. So far, the stock parameters are being passed:</p>

<pre><code>var params = "title=" + document.getElementById("title").value + 
             "&amp;url=" + document.getElementById("url").value + 
             "&amp;snippet=" + document.getElementById("snippet").value +
             "&amp;tags=" + document.getElementById("tags").value +
             "&amp;status_bookmark=" + document.getElementById("status_bookmark").value +
             "&amp;comment=" + document.getElementById("comment").value +
             "&amp;status_comment=" + document.getElementById("status_comment").value;
</code></pre>

<p>I'm attempting to append additional form elements to this parameter string, which are:</p>

<pre><code>var i, lng = document.getElementById('addbookmark').length;
// If the length property is undefined, then there is only one checkbox.
if (typeof lng === "undefined") {
    params + "&amp;topic-link-item-1=" + document.getElementById("topic-link-item-1").value;
    params + "&amp;topic-link-comment-box-1=" + document.getElementById("topic-link-comment-box-1").value;
}
else {
    for (i = 0; i &lt; lng; i++) {
        params + "&amp;topic-link-item-" + i + "=" + document.getElementById("topic-link-item-" + i).value;
        params + "&amp;topic-link-comment-box-" + i + "=" + document.getElementById("topic-link-comment-box-" + i).value;
    }
}
</code></pre>

<p>Here, I've used code taken from <a href="http://stackoverflow.com/questions/11838667/javascript-count-checked-checkbox">another StackOverflow article</a>, and as you can see, I'm trying to build up a series of paired parameters that match the ad hoc form elements I'm generating elsewhere via jQuery, which works.</p>

<p>However, these values appear not be getting passed via the form, while the other form elements are being passed.</p>

<p>Any suggestions?</p>

<p><strong>Update</strong></p>

<p>I've revised the code, per the suggestions, but it's not working:</p>

<pre><code>var i, formObj = document.form['addbookmark'], formObjLng = document.form['addbookmark'].length;
// If the length property is undefined, then there is only one checkbox.
if ((typeof formObjLng !== "undefined")) {
    for (i = 0; i &lt; formObjLng; i++) {
        if ((formObj.elements['topic-link-item-' + i].type == "checkbox") &amp;&amp; (formObj.elements['topic-link-item-' + i].checked)) {
            params = params + "&amp;topic-link-item-" + i + "=" + encodeURIComponent(document.getElementById("topic-link-item-" + i)).value;
            params = params + "&amp;topic-link-comment-box-" + i + "=" + encodeURIComponent(document.getElementById("topic-link-comment-box-" + i)).value;
        }
    }
}
</code></pre>

<p>As for the form, it's simply a form with an ID of "addbookmark", and to again state what I said earlier, everything else works with the exception of what Im attempting here.</p>
