Updating a Hidden Field in ASP.NET via JavaScript
<p>I inherited some JavaScript that I was told to integrate into our ASP.NET site.  I thought this would be straightforward but it's turning out to be a bit of a challenge.</p>

<p>The code looks something like this:</p>

<pre><code>&lt;SELECT id="Question1" name="Question" onchange="updateQuestion();"&gt;                 
&lt;OPTION value="notChosen"&gt;--Please Select One--&lt;/OPTION&gt;
&lt;OPTION value="in"&gt;India&lt;/OPTION&gt;
&lt;OPTION value="de"&gt;Germany&lt;/OPTION&gt;                     
&lt;OPTION value="fr"&gt;France&lt;/OPTION&gt;                
&lt;OPTION value="us"&gt;United States&lt;/OPTION&gt;                     
&lt;OPTION value="ch"&gt;Switzerland&lt;/OPTION&gt;                
&lt;/SELECT&gt; 
</code></pre>

<p>The goal is to get the value from this HTML control into ASP.NET, however this control itself is being dynamically generated by another chunk of javascript, so I can't just change this to an asp.net control.  My solution was to add the onchange="updateQuestion();" method, this JS will take these SELECT tags and place the values into an ASP.NET control:</p>

<pre><code>function updateSecQ() {
    var sQuestion = document.getElementById('&lt;%=sQuestion.ClientID%&gt;');
    sQuestion.Value = "";
    var questions = document.getElementsByName('Question');
    for (question in questions) {
        if (questions[question].value != null)
            sQuestion.Value += questions[question].value + ",";
    }
    alert(sQuestion.Value);
}
</code></pre>

<p>As you can see, that's looking to update an ASP.NET control:
    <code>&lt;asp:HiddenField ID="sQuestion" runat="server" value="" /&gt;</code></p>

<p>This appears to all work, however when I goto the server side on the form submit I see that sQuestion.Value is still = "".</p>

<p>I'm not quite sure what I've done wrong here, any input would be much appreciated.  Thank you for your time.</p>
