technocrat
technocrat

Reputation: 735

greasemonkey code modification

A user has helped me find hidden values in a page and display it using alert. If there are radio buttons and one of them is related to this value,is there a way to select the radio button automatically rathar than displaying the value in alert box.. Thanks...

the code is as follows:

var inputs = document.getElementsByTagName('input');

for (i=0; i<inputs.length; i++) {
  if (inputs[i].getAttribute("name") == "ans") {
    alert(inputs[i].getAttribute("value"));
  }
}

this "value" must be selected in the radio button rather than alerting...

the html code is here:

Thus i need the option with value "Underlying Unity of Human Behaviour" to be checked after the page loads.. Thanks

  

<table style="margin-left:20px" align="center" width="450" border=0> <form name="bloogs" action="/mywebsite.php" id="bloogs" method="post" > <tr><td align="left" class="formHeading" colspan=2 ><b><font size="4px"> world</font></b></td> <td class="log" align="right" width=150 ><a href="website.php">Back to <br>Regular Index</a></td> </tr> <tr> <td colspan=3 align="right" valign="top" height="30px"><div id="Time" style=""></td> </tr> <input type="hidden" name="ans" value="Underlying Unity of Human Behaviours" /> <input type="hidden" name="pno" value="3" /> <input type="hidden" name="quesid" value="3005" /> <tr> <td valign="top" width=20><b>3.&nbsp;</b> </td> <td class="ques" colspan=2>Which is the basic assumption of case study?</td> </tr> <tr> <td></td> <td height="10" class="Textbold" colspan=2></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt1" style="" ><input type="radio" id="r1" name="opt" value="Data"> Data</div></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt2" style="" ><input type="radio" id="r2" name="opt" value="Necessity"> Necessity</div></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt3" style="" ><input type="radio" id="r3" name="opt" value="Observation"> Observation</div></a></td> </tr> <tr><td></td> <td class="" colspan=2><div class="ans" id="opt4" style="" ><input type="radio" id="r4" name="opt" value="Underlying Unity of Human Behaviours"> Underlying Unity of Human Behaviours</div></td> </tr> <tr><td></td> <td height="20"> </td> </td> </tr> <tr height=50><td align='right' width=350 colspan=3><input class='button' id='checkans' value='Attempt' type='submit' name='checkans'/> <input class='button' id='' value='Skip' type='submit' name='skip'/></td></tr></form> </td> </tr> </table>

Upvotes: 0

Views: 187

Answers (1)

Gordon Gustafson
Gordon Gustafson

Reputation: 41259

Do you just want to check the radio button?

var inputs = document.getElementsByTagName('input');

for (i=0; i<inputs.length; i++) {
  if (inputs[i].getAttribute("name") == "ans") {
    inputs[i].checked = true;
  }
}

see here :D

Upvotes: 1

Related Questions