Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically selecting an <option> works in Opera, but not in Chrome
    primarykey
    data
    text
    <p>I have a userscript that has to change a whole list of options depending on 1 option in a select. In Opera this script works fine, but not in Chrome (Yes, jQuery is available).</p> <p>HTML:</p> <pre><code>&lt;select id="autoConfig-gametype" style="width: 100%;"&gt; &lt;option value="1" selected=""&gt;1. [RECOMMENDED] All latest Game-settings, Paladin, archers, simple tech smithy&lt;/option&gt; &lt;option value="2"&gt;2. No paladin, archers, simple tech system [TWMASTERS Settings]&lt;/option&gt; &lt;option value="3"&gt;3. No paladin, no archers. Packages, 3 lvl tech-system. [CLASSIC]&lt;/option&gt; &lt;/select&gt; &lt;select name="game::tech"&gt; &lt;option value="0"&gt;0: 10 level&lt;/option&gt; &lt;option value="1"&gt;1: 3 level (up to 15)&lt;/option&gt; &lt;option value="2" selected="selected"&gt;2: Simple&lt;/option&gt; &lt;/select&gt; </code></pre> <p>With jQuery I have used <code>attr</code> and <code>prop</code>, but both have no result in Chrome. The select that needs to be manipulated does not change.</p> <p>jQuery:</p> <pre><code>$("#autoConfig-gametype").change(function() { var value = $(this).val(); switch(value) { case "1": // Game &gt; Tech $("[name='game::tech'] option").removeProp("selected"); $("[name='game::tech'] option").removeAttr("selected"); $("[name='game::tech'] option:eq(0)").attr("selected",true); $("[name='game::tech'] option:eq(0)").prop("selected",true); break; case "2": // Game &gt; Tech $("[name='game::tech'] option").removeProp("selected"); $("[name='game::tech'] option").removeAttr("selected"); $("[name='game::tech'] option:eq(1)").attr("selected",true); $("[name='game::tech'] option:eq(1)").prop("selected",true); break; case "3": // Game &gt; Tech $("[name='game::tech'] option").removeProp("selected"); $("[name='game::tech'] option").removeAttr("selected"); $("[name='game::tech'] option:eq(2)").attr("selected",true); $("[name='game::tech'] option:eq(2)").prop("selected",true); break; } }); </code></pre> <p>I am kind of stuck here right now, because I am making this script for someone who only uses Chrome.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload