javascript - Greasemonkey to change value of Radio buttons in a form? -
i writing greasemonkey/tampermonkey script , need turn on radio buttons depending on name , value of radio control.
this how looks:
<input type="radio" name="11" value="xxx" class="radio"> <input type="radio" name="11" value="zzzz" class="radio"> so want set buttons have name of 11 , value of zzzz checked.
this super easy when use jquery. here's complete script:
// ==userscript== // @name _radio button check // @include http://your_site/your_path/* // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @grant gm_addstyle // ==/userscript== /*- @grant directive needed work around design change introduced in gm 1.0. restores sandbox. */ $("input[name='11'][value='zzzz']").prop ('checked', true); the input[name='11'][value='zzzz'] jquery selector gets <input>s have initial value zzzz, if in group of radio buttons name="11".
reference:
important: above works on pages but, on ajax-driven pages, need use ajax-aware techniques. because greasemonkey script run before checkbox care loaded.
one way deal the waitforkeyelements utility. so:
// ==userscript== // @name _radio button check // @include http://your_site/your_path/* // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @require https://gist.github.com/raw/2625891/waitforkeyelements.js // @grant gm_addstyle // ==/userscript== /*- @grant directive needed work around design change introduced in gm 1.0. restores sandbox. */ waitforkeyelements ("input[name='11'][value='zzzz']", selectradiobutton, true); function selectradiobutton (jnode) { jnode.prop ('checked', true); } old answer "state of art" :) when question asked:
// ==userscript== // @name _radio button check // @include http://your_site/your_path/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js // ==/userscript== $("input[name='11'][value='zzzz']").attr ("checked", "checked");
Comments
Post a Comment