Andreas Jeansson
Andreas Jeansson

Reputation: 120

jQuery automatically selects option in select box. How to disable?

I'm building a website in Wordpress and I have a couple of selectboxes that is used for navigation between different posts. Pretty basic stuff:

<select id="all" name="allPostsAllSelect">
<option value="-1" style="font-weight:bold">--All programmes--</option>
<option value="http://site.domain/articleid/">Article 1</option>
...
</select>

When an item is selected the current page is loaded and here my problems begin. Somehow the selected option remains selected on the article page, and I am not using frames ;)

I have tried to set breakpoints in firebug and it seems that jquery somewhere in it's over optimized totally unreadable code "helps" me to magically select the option that matches the current URL. I have tried to google this but I can't find anything.

Seems that wordpress uses

jquery.js?ver=1.7.2
jquery.cycle.all.js?ver=3.4
jquery.metadata.v2.js?ver=3.4
jquery.touchwipe.1.1.1.js?ver=3.4

Needless to say I do not want this "help", I want the first item to always be selected unless i say something different. What the hell is going on and how can I turn it off?

Thank you!

Upvotes: 0

Views: 201

Answers (2)

s_ha_dum
s_ha_dum

Reputation: 2850

jQuery, strictly speaking, isn't doing this. The jQuery library does pretty much nothing. Nor am I aware of anything in WordPress that would do this automatically, and WordPress doesn't load any of those scripts on the front end by default (about 90% sure). Something in your theme or a plugin is doing this. Try to figure out which one by disabling your plugins one by one and switching to a default theme. It would be easier if I could see your site. Do you have a public URL?

Upvotes: 1

jrummell
jrummell

Reputation: 43087

You could set the selected value yourself:

$(document).ready(function () {
  // select a specific option
  $("#all").val("-1");
});

Or to clear the selected option (will select first by default):

$(document).ready(function () {
  $("#all").val("");
});

Upvotes: 1

Related Questions