document.getElementById('form:b2').click(); Not working in Mozilla

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsuns82
    New Member
    • Mar 2007
    • 58

    document.getElementById('form:b2').click(); Not working in Mozilla

    Hi all,

    I am trying to click a button using javascript code as follows

    [code=javascript]document.getEle mentById('form: b2').click(); [/code]
    The above mentioned code working properly in IE but not working in Mozilla.

    Is thr any other alternative javascript code inorder to click a button???

    Thanks&Regards,
    sundar.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by gsuns82
    Hi all,

    I am trying to click a button using javascript code as follows

    * document.getEle mentById('form: b2').click();
    The above mentioned code working properly in IE but not working in Mozilla.

    Is thr any other alternative javascript code inorder to click a button???

    Thanks&Regards,
    sundar.

    Will you post your HTML code.
    Then it ll be better to solve your problem.

    Kind regards,
    Dmjpro.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      hi ...

      the typical way is as follows:

      [HTML]<script type="text/javascript">
      function do_the_click(bt n) {
      alert('you clicked the button with id = ' + btn.id);
      }
      </script>

      <input type="button" value="click me" id="clk_btn" onclick="do_the _click(this);"/>[/HTML]

      kind regards

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Are you sure "form:b2" is the id and not the name?

        Comment

        • gsuns82
          New Member
          • Mar 2007
          • 58

          #5
          Originally posted by acoder
          Are you sure "form:b2" is the id and not the name?
          Alternative script method for the following:
          [code=javascript]
          document.getEle mentById('formI D:fieldId').cli ck();
          [/code]
          Thanks&Regards,
          sundar

          Comment

          • gsuns82
            New Member
            • Mar 2007
            • 58

            #6
            Originally posted by gits
            hi ...

            the typical way is as follows:

            [HTML]<script type="text/javascript">
            function do_the_click(bt n) {
            alert('you clicked the button with id = ' + btn.id);
            }
            </script>

            <input type="button" value="click me" id="clk_btn" onclick="do_the _click(this);"/>[/HTML]

            kind regards

            Alternative script method for the following:

            document.getEle mentById('formI D:fieldId').cli ck();

            Thanks&Regards,
            sundar

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by gsuns82
              Alternative script method for the following:

              document.getEle mentById('formI D:fieldId').cli ck();
              Are you giving the solution or asking a question?

              Show the generated HTML, not the JSP. View source on the browser and post the HTML/Javascript.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Sundar, please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

                Comment

                • Chepech
                  New Member
                  • Apr 2008
                  • 1

                  #9
                  Originally posted by gits
                  hi ...

                  the typical way is as follows:

                  [HTML]<script type="text/javascript">
                  function do_the_click(bt n) {
                  alert('you clicked the button with id = ' + btn.id);
                  }
                  </script>

                  <input type="button" value="click me" id="clk_btn" onclick="do_the _click(this);"/>[/HTML]
                  Try this:

                  [HTML]document.getEle mentById('clk_btn').click();[/HTML]

                  clk_btn is the ID of your button, if the id is unique in the document that will work. IE and Mozilla have different ways of handling ID serches in the DOM tree thats why it worked on IE. IE creates all the DOM structure into the JS object hierarchy, which means that you can locate this button (assuming its inside a FORM called f1) using something like this...

                  Code:
                  document.f1.clk_btn
                  However, that's not a JavaScript standard (acording to W3C). Unlike IE, Mozilla is a http://www.w3c.org standard compliant browser (sort of), so that will not work in Mozilla.

                  Comment

                  Working...