How to Reset dropdown (select box) value to default using jquery

You can reset the dropdown in many ways. Here we will discuss what are all the way we can reset dropdown using jquery.

First create a function for reset dropdown value. or you can use particular line with onclick attribute directly.

function resetDropDown(){
	// code for reset dropdown

Method 1: Find first option of the dropdown and change its selected attribute value.

$("dropdownSelector").find("option:first").attr("selected", "selected");
$("dropdownSelector option:eq(0)").attr("selected", "selected");

Method 2: Set the default value to dropdown

$("dropdownSelector").val(0); // 0 is the value of first option or default option
var firstVal = $("dropdownSelector").find("option:first").val();

Method 3: Using selectedindex

$("dropdownSelector").get(0).selectedIndex = 0;

Method 4: using option’s text to reset value

$("dropdownSelector option:contains("OPtion Text here")").attr("selected","selected"); 

Leave a Reply

Your email address will not be published. Required fields are marked *