Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click second button on form

Status
Not open for further replies.

claudiodi

Technical User
Jul 24, 2010
3
IT
I am new to this forum, Hi everybody

I am trying to write a greasemonkey javascript code to automate submission of a form

the form has no name so I used this code to identify it in the array of forms and submit:

document.getElementsByTagName('form')[1].submit();

it ALMOST works but the problem is that the form has 2 buttons (see below) and my code clicks on the first one while I want to click on the second one;

question: how do I identify the second button?
(it has no "id" or "name", only a "value"; there's a "class" in the TD tag before if it can help)

Thanks
Claudio

-----

<td class="license2">
<input type='submit' value="Save" class="btn" onclick='document.getElementById("submit_elem").value="save";' />
</td>

<td class="license3">
<input type='submit' value="Submit" class="btn" onclick='document.getElementById("submit_elem").value="submit";'/>
</td>


 
ok, I found a solution myself:

document.getElementsByTagName('form')[1].elements[15].click();

if someone knows a more elegant solution than "counting" elements I'm still interested to hear
 
Why not give your buttons an ID and just use getElementById directly.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
That's what I would do indeed.

But it's not my web site, I am trying to automate an existing website which I can't edit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top