Note that there are some explanatory texts on larger screens.

plurals
  1. POExclude first value on jquery function on mvc dropdown list
    primarykey
    data
    text
    <p>I have this MVC web application with dropdowns:</p> <pre><code>@Html.DropDownListFor(model =&gt; model.Questions1, (SelectList)ViewData["Questions"], "Select&gt;&gt;", new { id = "Questions1", Name = "Questions1"}) @Html.DropDownListFor(model =&gt; model.Questions2, (SelectList)ViewData["Questions"], "Select&gt;&gt;", new { id = "Questions2", Name = "Questions2"}) </code></pre> <p>And this jquery:</p> <pre><code>// Build a javascript array with all of the select names/values var options = new Array(); $('#Questions1 option').each(function() { $this = $(this); options.push({ Name: $this.text(), Value: $this.val() }); }); // Create a function for re-building a select minus the chosen option var rebuildSelect = function($selOption, $select) { $previouslySelected = $select.find(':selected'); $select.empty(); for (var i = 0; i &lt; options.length; i++) { var opt = options[i]; if (opt.Value != $selOption.val()) { if ($previouslySelected.val() == opt.Value) { $select.append('&lt;option value="' + opt.Value + '" selected="selected"&gt;' + opt.Name + '&lt;/option&gt;'); } else { $select.append('&lt;option value="' + opt.Value + '"&gt;' + opt.Name + '&lt;/option&gt;'); } } } } // Wire up the event handlers var $Questions1 = $('#Questions1'); var $Questions2 = $('#Questions2'); $Questions1.change(function() { rebuildSelect($(this), $Questions2); }); $Questions2.change(function() { rebuildSelect($(this), $Questions1); }); // Go ahead and run the function on each box to remove the default entries from the other box rebuildSelect($Questions1.find(':selected'), $Questions2); rebuildSelect($Questions2.find(':selected'), $Questions1); </code></pre> <p>What the jquery code do is to remove the selected value on the first dropdown on the second dropdown so the user won't able to chose two same question.</p> <p>My problem is the default value of the dropdown which is "Select>>" is being removed from the second dropdown.</p> <p>Any idea how I can exclude the "Select>>"? Thanks in advance!</p> <p><a href="http://jsfiddle.net/n5k99/4/" rel="nofollow">Fiddle</a></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.
    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