Help needed writing a Greasemonkey user script

M

MKR

I need some help writing a Greasmonkey user script. An application that
I use generates HTML pages with tags like this:

<input type="button" name="9999" value="1234567890"
onClick="showitem('1234567890'); return false">

Sometimes I just want to copy the item number (i.e. the "value"
attribute), other times I actually want to click the button and see the
item. Right now I can see the item number as a button label, but I
cannot copy its value. What I want to do is to use a Greasmonkey user
script to replace the buttons with some like:

<a href="./info/1234567890.htm">1234567890</a>

Can someone show me how to do that in JavaScript?

Many thanks.
 
M

Martin Honnen

MKR said:
<input type="button" name="9999" value="1234567890"
onClick="showitem('1234567890'); return false">

Sometimes I just want to copy the item number (i.e. the "value"
attribute), other times I actually want to click the button and see the
item. Right now I can see the item number as a button label, but I
cannot copy its value. What I want to do is to use a Greasmonkey user
script to replace the buttons with some like:

<a href="./info/1234567890.htm">1234567890</a>

// assuming that input type="button" is the first element with
// that name 9999:
var button = document.getElementsByName('9999')[0];
if (button != null) {
var link = document.createElement('a');
link.href = './info/' + button.value + '.htm';
link.appendChild(document.createTextNode(button.value));
button.parentNode.replaceChild(link, button);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top