Resetting all other select menus when any one is selected (jQuery and WordPress)
I need all other select menus to be reset (without hitting submit) when any one is selected. Here is an example with just two menus but I will probably need it to work with four. (select one, other three are reset to default values)
Example menu 1 :
<select name="jj_register_options[number]" id="jj_register_options[number]">
<option value="">Front Page</option>
<option class="level-0" value="1115">Cart</option>
<option class="level-0" value="1143">Checkout</option>
<option class="level-1" value="1148"> Checkout â Pay</option>
<option class="level-1" value="1149"> Order Received</option>
<option class="level-0" value="1009">Checkout</option>
<option class="level-0" value="1116">Image Store</option>
<option class="level-0" value="971">Logout</option>
<option class="level-0" value="967">Lost Password</option>
<option class="level-0" value="1042">Members</option>
<option class="level-0" value="1144">My Account</option>
</select>
Example menu 2
<select name="jj_register_options[categories]" id="jj_register_options[categories]" class="">
<option class="level-0" value="1">Uncategorized (0)</option>
<option class="level-0" value="5">testy test (1)</option>
<option class="level-0" value="7">Help & Support (1)</option>
<option class="level-0" value="8">Themes (0)</option>
<option class="level-0" value="24">Entertainment (1)</option>
<option class="level-0" value="28">Lifestyle (1)</option>
</select>
When one is clicked the other needs to reset.
I have this code but it is not working.
$('#jj_register_options[number]').change(function(){
$('#jj_register_options[categories]').prop('selectedIndex',0);
});
$('#jj_register_options[categories]').change(function(){
$('#jj_register_options[number]').prop('selectedIndex',0);
});
Any help would be appreciated. I am good with PHP, but have almost no jQuery / javascript knowledge,
jQuery uses
[
and]
for attribute selectors, your selector selects an element with ID ofjj_register_options
that hascategories
attribute. Escape them or use different identifiers. the.prop()
method will work as it is if you are using jQuery 1.6+.Thanks to brasofilo and Harke for the answer.
PLease see the jquery code used for reference. This was used in conjunction with three separate select boxes with ids ‘jj_register_cats’ , ‘jj_register_tag’ and ‘jj_register_page’. Note I have included jQuery rather than $ as this is how wordpress likes it;-) Thanks again.
});
The
id
doesn’t have to follow theoption[key]
format, as the form processing is based onname
notid
.It’s easier and cleaner to target them this way.