Reputation: 6006
I am using materlize. The problem is i have to make an option selected using jquery. All working fine when i am trying to get the value of selected option. But the only problem is the selected ption is not getting highligted. It always shown the default option text "Choose An Option"
My Html code is
<select id="redirect_select" name="redirect_select" onchange="showRedirect();">
<option value="">Choose An Option</option>
<option value="0">Use Redirect URL</option>
<option value="1">Use Success Message</option>
</select>
And my script code is
$("#redirect_select").val("0").trigger("onchange");
Upvotes: 0
Views: 406
Reputation: 20590
What you have to do is to:
val("0")
without triggerfunction showRedirect(){
val = $("#redirect_select").val();
alert("value is: "+val)
$("#redirect_select").val("0");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="redirect_select" name="redirect_select" onchange="showRedirect();">
<option value="">Choose An Option</option>
<option value="0">Use Redirect URL</option>
<option value="1">Use Success Message</option>
</select>
Upvotes: 2