views:

55

answers:

1

HI, i need a greasemonkey code for a web page. The page has hidden input type and value. I need a gm script which can alert the value of the hidden input object as soon as the page loads.

The input tag is present in a form with:

form id="bloog" method="post" action= "/newpage.php" name="bloog">

The hidden content is present as:

<input type="hidden" value="abcd" name="ans">

now as soon as the page loads the value abcd must come in the alertbox.. some body please help me i've been trying for these...

A: 

Something like this might work.

// ==UserScript==
// @name          Script Name Here
// @namespace     http://www.yourdomain.com
// @description   An Greasemonkey script that hides alerts hidden field value
// @include       *
// ==/UserScript==

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

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

Read Get Started With Greasemonkey on WebMonkey

jessegavin
awesome... dude... @jessegavin... thanks
muqtar
the code works as expected.. Instead of showing the value in alert box,can the script automatically select the radio button corresponding to that value... Thanks
muqtar
yes. yes it can
jessegavin