Using js (jquery) to select only the 1st item in a select co

Posted by riche on 10-Feb-2015 15:29

I have a filter page and would like to reset the values back to default whenever they enter or leave (don't care which one) the page. The first item in the select is "Choose..." with a value of "". I added another property to make it allow multiple. So, if they choose multiple options and filter or cancel, I want it to move the selection back to only Choose... (or empty value). I've created the page hide or page show event and tried many different ways, all of which have failed. I have tried casting Progress('selectName').val(0); and Progress('selectName').val(""); and many variants of jquery, like $("select[name='testSelect']:selected").first().attr("selected", false); and others. If I have mutliple on, do I need to use the checked property instead? Do I need to call a refresh somehow (looked and didn't see one)?

Posted by pantipov on 13-Feb-2015 04:31

Hi Riche,

please try this code:

$("[dsid=selectName]").val("Vici").selectmenu("refresh", true);

Let me know if you have any questions.

All Replies

Posted by egarcia on 10-Feb-2015 15:52

Hello,

I believe that you need a line of code like the following:

   $("[dsid=selectName]").val("Vici").change();

I hope this helps.

Posted by riche on 12-Feb-2015 12:34

This actually only half works for me. It does make it so that it only shows Choose..., but if they click on it to get the popup of choices, the choices are still checked. I looked at the values of the options in the debugger and they all have the selected property as false and the main control has a selectedindex of -1, but it still has them selected when it opens.

Posted by pantipov on 13-Feb-2015 04:31

Hi Riche,

please try this code:

$("[dsid=selectName]").val("Vici").selectmenu("refresh", true);

Let me know if you have any questions.

This thread is closed