1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with Click()

Discussion in 'Web Design, HTML And CSS' started by w!ck3d, Jun 18, 2009.

  1. w!ck3d

    w!ck3d New Member

    Joined:
    Sep 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I'm new to JS and i'm trying to write a script that will do something like this:

    If on page #1
    //click button1
    else if on page#2
    //click button2
    else
    //click button3

    To click a button i use:
    document.Form_Name.Button_Name.click();

    It works fine as long as i know the form name and the button name like clicking the search button in google would be:
    document.f.btnG.click();

    But some forms don't have a name. All they have is something like:
    <form action="Link" method="post" onsubmit="this.submit.disabled=true;">
    .
    .
    .
    and the button is:
    <input name="submit" type="submit" onload="this.disabled=false;" value="OK">


    How can i click such a button?
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    You can loop through all forms on a document this way :

    Code:
    var AllForms = document.forms;
    var TForm;
    for (i = 0; i < AllForms.length; ++i)
    {
          TForm = document.forms[i];
          // To click a button
          TForm.mybutton.click();
    }
    It depends on you to check which form you want : you can check properties of TForm before clicking button.
     

Share This Page