0

Here is the HTML:

<p><input type="radio" value="Number1" name="Name" />Yes</p>
<p><input type="radio" value="Number2" name="Name" />No</p>
<p><input type="radio" value="Number3" name="Name" />Maybe</p>

Yes, they all have the same name - this isn't my site, so I can't change that.
Is there a way to check Number2 / No automatically with a simple GM script?

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
spamgirl
  • 21
  • 1
  • 2
  • Duplicate of [Greasemonkey to change value of Radio buttons in a form](http://stackoverflow.com/questions/6539300/greasemonkey-to-change-value-of-radio-buttons-in-a-form) and several others. – Brock Adams Aug 23 '12 at 00:05

2 Answers2

1

Here's how with pure javascript:

var radBtn      = document.querySelector (
    "p input[type=radio][name='Name'][value='Number2']"
);
radBtn.checked  = true;


Here's how with jQuery:

$("p input[type=radio][name='Name'][value='Number2']").prop ("checked", true);



Note that you want to make the selector fairly specific to avoid unexpected behavior.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
0
var labels = document.getElementsByTagName('label'); 
for (var i = 0; i < labels.length; ++i) { 
    if (labels[i].textContent == "Instagram") { 
        labels[i].click(); 
    }
}
Craig
  • 556
  • 1
  • 8
  • 23
  • That doesn't work because I don't have label tags, and I don't have Instagram in the code :) I tried altering that to use it for my needs (using the input tag and "Number2"), but it didn't work. I need to be able to pull the value from the input tag, I assume. That's why, after reading all the other threads here on the same topic, I posted. – spamgirl Aug 21 '12 at 19:26