snipt

Ctrl+h for KB shortcuts

C#

HTML Select list to open a custom URL based on selected value

1
2
3
4
5
6
<select name="sortby"  onchange="window.location = '@onChangeUrl' + encodeURI(this.value)">
    @foreach(KeyValuePair<string, int> option in SPModel.SortOptions)
    {
        <option value="@option.Value">@option.Key</option>
    }									
</select>
https://snipt.net/embed/1e15e79ff0d93227ae62cff6330ebea3/
/raw/1e15e79ff0d93227ae62cff6330ebea3/
1e15e79ff0d93227ae62cff6330ebea3
csharp
C#
7
2019-07-17T08:50:36
True
False
False
Feb 05, 2014 at 07:22 PM
/api/public/snipt/111269/
html-select-list-to-open-a-custom-url-based-on-selected-value
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">&lt;</span><span class="k">select</span> <span class="n">name</span><span class="p">=</span><span class="s">&quot;sortby&quot;</span> <span class="n">onchange</span><span class="p">=</span><span class="s">&quot;window.location = &#39;@onChangeUrl&#39; + encodeURI(this.value)&quot;</span><span class="p">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">@foreach</span><span class="p">(</span><span class="n">KeyValuePair</span><span class="p">&lt;</span><span class="kt">string</span><span class="p">,</span> <span class="kt">int</span><span class="p">&gt;</span> <span class="n">option</span> <span class="k">in</span> <span class="n">SPModel</span><span class="p">.</span><span class="n">SortOptions</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">&lt;</span><span class="n">option</span> <span class="k">value</span><span class="p">=</span><span class="s">&quot;@option.Value&quot;</span><span class="p">&gt;</span><span class="n">@option</span><span class="p">.</span><span class="n">Key</span><span class="p">&lt;/</span><span class="n">option</span><span class="p">&gt;</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">&lt;/</span><span class="k">select</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
forms, html, razor

Text only

Fill in form with test results.

1
2
3
4
5
6
$("input[type='text']").val("test"); 
$("input[name='email']").val("[email protected]");
$("input[type='email']").val("[email protected]");
$("textarea").val("This is a test.");
$("select").each(function(){$(this).children().last().attr("selected","selected");});
$("input[type='checkbox']").attr('checked', true);
https://snipt.net/embed/0c8821e4e847c0fd4ac03b8fdbb672de/
/raw/0c8821e4e847c0fd4ac03b8fdbb672de/
0c8821e4e847c0fd4ac03b8fdbb672de
text
Text only
6
2019-07-18T15:15:54
True
False
False
/api/public/snipt/81249/
fill-in-form-with-test-results
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>$(&quot;input[type=&#39;text&#39;]&quot;).val(&quot;test&quot;); </span><span id="L-2"><a name="L-2"></a>$(&quot;input[name=&#39;email&#39;]&quot;).val(&quot;[email protected]&quot;); </span><span id="L-3"><a name="L-3"></a>$(&quot;input[type=&#39;email&#39;]&quot;).val(&quot;[email protected]&quot;); </span><span id="L-4"><a name="L-4"></a>$(&quot;textarea&quot;).val(&quot;This is a test.&quot;); </span><span id="L-5"><a name="L-5"></a>$(&quot;select&quot;).each(function(){$(this).children().last().attr(&quot;selected&quot;,&quot;selected&quot;);}); </span><span id="L-6"><a name="L-6"></a>$(&quot;input[type=&#39;checkbox&#39;]&quot;).attr(&#39;checked&#39;, true); </span></pre></div> </td></tr></table>
"dummy info", debugging, forms, test, testing