Adding an item to a drop-down list without selecting an item

I have a wherr form. I fill in the name of the element and immediately after I hit it, adds the element to the drop-down list and is automatically selected. Is there any way not to use this newly added item?

My code that adds the item is as follows

$("#userGroup_groups").append("<option value="41" selected="selected">item</option>"); 
+4
source share
4 answers

remove selected

 $("#userGroup_groups").append("<option value=\"41\" >item</option>"); 
+5
source

Do not set selected properties for new items

 $("#userGroup_groups").append('<option value="41">item</option>'); 
+1
source

check the page after returning to the page_load event and set AutoPostBack = "true" in asp: ddl control

  if (!IsPostBack) { LoadInfoDDL(); } 

therefore it will solve your problem.

0
source

You must use a combination of "and" when performing such actions

 $("#userGroup_groups").append( "<option value='41' selected='selected'>item</option>" ); 
-1
source

Source: https://habr.com/ru/post/1338420/


All Articles