Using javascript to set value of hidden field then access value from serverside c# code
<p>I am using a nested html unordered list styled as a drop down. When the a tag within the inner lists list item is clicked it trigger some javascript which is supposed to set the value of a hidden field to the text for the link that was clicked.</p>

<p>The javascript seems to work - I used an alert to read the value from the hidden field but then when I try to put that value in the querystring in my asp.net c# code behind - it pulls the initial value - not the javascript set value.</p>

<p>I guess this is because the javascript is client side not server side but has anyone any idea how i can get this working</p>

<p><strong>HTML</strong></p>

<pre><code>    &lt;div class="dropDown accomodation"&gt;
    &lt;label for="accomodationList"&gt;Type of accomodation&lt;/label&gt;
    &lt;ul class="quicklinks" id="accomodationList"&gt;
        &lt;li&gt;&lt;a href="#" title="Quicklinks" id="accomodationSelectList"&gt;All types
     &lt;!--[if IE 7]&gt;&lt;!--&gt;&lt;/a&gt;&lt;!--&lt;![endif]--&gt;

    &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt;
    &lt;ul id="sub" onclick="dropDownSelected(event,'accomodation');"&gt;
         &lt;li&gt;&lt;a href="#" id="val=-1$#$All types" &gt;All types&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href="#" id="val=1$#$Villa" &gt;Villa&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href="#" id="val=2$#$Studio" &gt;Studio&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href="#" id="val=3$#$Apartment" &gt;Apartment&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a class="last" href="#" id="val=4$#$Rustic Properties" &gt;Rustic Properties&lt;/a&gt;&lt;/li&gt;

    &lt;/ul&gt;
    &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt;
        &lt;/li&gt;&lt;/ul&gt;
    &lt;/div&gt;

&lt;input type="hidden" ID="accomodationAnswer" runat="server" /&gt;
</code></pre>

<p><strong>javascript</strong></p>

<pre><code>    if(isChildOf(document.getElementById(parentList),document.getElementById(targ.id)) == true)
{           

            document.getElementById(parentLi).innerHTML = tname;            
            document.getElementById(hiddenFormFieldName).Value = targ.id;
            alert('selected id is ' + targ.id + ' value in hidden field is ' +           document.getElementById(hiddenFormFieldName).Value);
}
</code></pre>

<p><strong>C# code</strong></p>

<pre><code>String qstr = "accom=" + getValFromLiId(accomodationAnswer.Value) + "&amp;sleeps=" + getValFromLiId(sleepsAnswer.Value) + "&amp;nights=" + getValFromLiId(nightsAnswer.Value) + "&amp;region=" +
getValFromLiId(regionAnswer.Value) + "&amp;price=" + Utilities.removeCurrencyFormatting(priceAnswer.Value);
</code></pre>
