Selecting all options from SelectList on button submit, before POST
asp.net-mvc, events, html, jquery, razor
Solution
you forgot the '.' at the className of selectionList:
submit_bttn.click(function () {
$('.selectionList select option').prop('selected', true);
});
- if the other select has the class selectionList then the selector should be 'select.selectionList option' (without the space) or just '.selectionList option'
edit: following your comment, to debug the problem, hook to the submit of the form to cancel it and see if all the options were selected:
//assuming you have only one form on the page.. $("form").submit(function(event){event.preventDefault() });
Problem
I have a User being reviewed drop down list, a SelectList of employees, and an empty Select List of Assigned Reviewers. When the admin double clicks an employee in the SelectList, it is appended into the Assigned Reviewers SelectList for the User being reviewed. Here is a visual picture: As you can see, I have jQuery selecting all options in the Assigned Reviewers SelectList, but if you click on one of them, it will deselect the other options and only append the selected option to a table. I would be able to disable this List, but I want the user to be able to remove from this List as well. I've tried using this code on bttn submit, but it only appended the one I had selected: ``` submit_bttn.click(function () { $('.selectionList select option').prop('selected', true); }); ``` I've even tried adding a second function on double click to append the selected attribute to the option, which works, but is removed once the user clicks out of scope. One thing I thought of doing was storing the values in hidden input fields, but I feel like this is unnecessary and would be more code for removing from the List. Also, I am using razor view: @Html.ListBox(selectList from viewbag). Any help would be splendid.