I have two dropdowns. When first change event then the second dropdownt loads some data from database.
For example when I select Phones Tablets from the first, then the second one should select Select Brand text. But it loads like below.
My second Dropdown list
<select id="mySelect1">
<option value="12103">Apple</option>
<option value="12124">Huawei</option>
<option value>Select Brand</option>
<option value="addnew">Enter your own</option>
</select>
So I use this code for set Selected Band text as selected value in Second dropdown. It uses the change event of my first dropdown list.
var text1 = 'Select Brand';
$("select option").filter(function() {
return $(this).text() == text1;
}).prop('selected', true);
My First Dropdown list
<select id="wcv_custom_product_cat" name="wcv_custom_product_cat" class="select2">
<option value="" selected="selected">Select</option>
<option value="341">Automotive</option>
<option value="50">Baby Kids</option>
<option value="49">Books</option>
<option value="48">Clothing Fashion</option>
<option value="47">Computing Gaming</option>
<option value="39">Electronics</option>
<option value="40">Food Grocery</option>
<option value="114">Home Kitchen</option>
<option value="44">Office Stationary</option>
<option value="43">Phones Tablets</option>
<option value="41">Health Beauty</option>
<option value="115">Industrial</option>
<option value="42">Sports Fitness</option>
<option value="45">Misc</option>
</select>
I refer those
jQuery - setting the selected value of a select control via its text description
How can I change my code?