Click here to Skip to main content
15,890,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code to set a value for the drop down list.
Drop down is #dropdown
Value to be selected is -1.

JQuery code for setting a drop down list.
Posted
Comments
Thanks7872 11-Nov-14 9:10am    
$("#Id_Of_Dropdown").val(-1);
raghunath sahoo 14-Nov-14 5:25am    
Thanks it helped..
Thanks7872 14-Nov-14 5:32am    
Cheers....

1 solution

If you pass the negative value as parameter to the val method it automatically add new blank option to the dropdownlist. Dropdown list should contains the value and text attributes for the each option then only your above method will work.
eg.
<option selected="selected" value="1">.NET Framework</option>
<option value="2">SQL Server</option>
<option value="3">ASP.NET</option>
<option value="4">C#.NET</option>
<option value="5">ADO.NET</option>
<option value="6">AJAX.NET</option>


and your method should be like -$("#dropdown").val(4);
it will select "C#.NET" option because we have provided value="4" for that option.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900