Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery unselect dropdown menu

I have a dropdown menu for states. The first option is 'Please select state' and its value is 0 but a state is always selected it as the user picks a state from a previous page and it somehow gets state and selects it. I want it to be at value 0.

I have this code....

$('#shipstate option').attr('selected', '');

but this sets all my options to selected.

What Am I doing wrong?

like image 875
user1269625 Avatar asked Nov 29 '25 16:11

user1269625


1 Answers

You want to set the value of an element that happens to be a select to 0, now turn this phrase into jquery:

$('#shipstate').val(0) 
like image 108
cernunnos Avatar answered Dec 02 '25 07:12

cernunnos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!