BigJazzz BigJazzz - 2 years ago 110
HTML Question

Inject Javascript to select all radio buttons with specified value

Slightly odd question, but I'm trying to find a way (if possible) to select all radio buttons that have the same value. We regularly get hundreds of spam accounts signing up on our website, and it would be easier to set all radio buttons to "Reject" and double-check to make sure there's no legitimate ones, as opposed to constantly clicking on a radio button. (Lazy is my middle name, yes.)

Is this possible? If so, how? I haven't got access to the actual web pages to code in a button to do just this yet, but it's something I'm looking at long term. Right now though, I need something quick and dirty to do what I want it to do. I'm using Chrome, and can use Greasemonkey if that's required.

The value to select by is


A snippet of code that's being used. If it's of any consequence, our forum is running Xenforo:

<label for="ctrl_users16667action_reject">
<input type="radio" name="users[16667][action]" value="reject" class="Disabler" id="ctrl_users16667action_reject">
Reject and delete with rejection reason:
<ul id="ctrl_users16667action_reject_Disabler" class="disablerList">
<input type="text" name="users[16667][reject_reason]" value="" size="45" placeholder="Optional" class="textCtrl" id="ctrl_users16667reject_reason">

Answer Source

You're looking for a bookmarklet or a GreaseMonkey (or similar) script.

Re bookmarklets, you can use the javascript: pseuedo-protocol to run script on the page you're looking at from your bookmarks manager. Just make the URL in your bookmark:

javascript:(function() { /* ...your code here ...*/ })();

Because it has to be URI-encoded, you can find "bookmarklet generators" out there to handle that part for you.

Alternately, there are GreaseMonkey, TamperMonkey, and similar add-ons/extensions for browsers.

Then it's a trivial matter of selecting the relevant radio buttons:

$('input[type=radio][value="reject"]').prop('checked', true);

So if jQuery is already loaded on the page in question, you could use this as a bookmarklet:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download