Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting html select value on postback
    primarykey
    data
    text
    <p>I'm having a bit of trouble here, hoping someone can help:</p> <p>I am dynamically populating an html select element in a razor script and onChange I am hoping to get this posted value. It is posting back as the page is refreshing but I don't seem to be getting the value of the select; The reason I know is that I am passing a category and filtering on it. This filtering works when I change the querystring in the URL manually and post it.</p> <p>Razor Script:</p> <pre><code> @using umbraco.MacroEngines @inherits DynamicNodeContext @{ dynamic rootNode = @Model.NodeById(1066); DynamicNodeList list = rootNode.Descendants(); List&lt;dynamic&gt; categories = new List&lt;dynamic&gt;(list.Cast&lt;dynamic&gt;()); List&lt;string&gt; alias = new List&lt;string&gt; { "GeneralPage" }; var filtered = categories.Where(n =&gt; alias.Contains(n.NodeTypeAlias)); } &lt;form method="post" action=""&gt; &lt;select id="selectCategory" name="selectCategory" onchange="this.form.submit(); alertMe(selectCategory)"&gt; @foreach (var node in filtered) { &lt;option value="@node.Name"&gt;@node.Name&lt;/option&gt; } &lt;/select&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; function alertMe(selectCategory) { alert(selectCategory) } &lt;/script&gt; </code></pre> <p>You'll notice I have a function to alert the selected value but this is coming back as [object HTMLSelectElement]</p> <p>I can post more code if needed to show what's happening on the server, but as I said the filtering DOES work, however I am trying capture the value in the following way:</p> <pre><code>string category = Request["selectCategory"]; if (category != null) { </code></pre> <p>Any help much appreciated. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload