Firefox submits form on hit another button...

Discussion in 'Javascript' started by Peet, Dec 6, 2005.

  1. Peet

    Peet Guest

    Hi there,

    Do somebody have some ideas about this behaviour?

    I have a struts application. It has a jsp which has a form and two
    buttons, one of them is html:submit, and the other is html:button.

    Submit has to post the form, of course, that works correctly on all of
    the browsers.
    But the other button has an onclick event declared. It calls the
    implemented javascript function in IE and in Opera, too, but Firefox
    submits the form as well when I hit submit button...

    Thanks in advance.
    Peter
    Peet, Dec 6, 2005
    #1
    1. Advertising

  2. Peet

    Tony Guest

    >But the other button has an onclick event declared. It calls the
    >implemented javascript function in IE and in Opera, too, but Firefox
    >submits the form as well when I hit submit button...


    onclick="doSomething();return false;"

    Not tested, but should work.

    "...submits the form as well when I hit submit button..."
    Of course - it's a submit button!
    Tony, Dec 6, 2005
    #2
    1. Advertising

  3. Peet

    web.dev Guest

    Peet wrote:
    > Hi there,
    >
    > Do somebody have some ideas about this behaviour?
    >
    > I have a struts application. It has a jsp which has a form and two
    > buttons, one of them is html:submit, and the other is html:button.
    >
    > Submit has to post the form, of course, that works correctly on all of
    > the browsers.
    > But the other button has an onclick event declared. It calls the
    > implemented javascript function in IE and in Opera, too, but Firefox
    > submits the form as well when I hit submit button...
    >
    > Thanks in advance.
    > Peter


    When you have a button and you don't explicity declare a type for it,
    the default type becomes a "submit" type. Other browsers honor this
    except for IE, which defaults it to just a "button" type.

    For example:

    <form>
    <button>
    </form>

    Except for IE, browsers will do a submit when the button is clicked.

    <form>
    <button type = "button">
    </form>

    Now, when you click on the button it will not do a submit.
    web.dev, Dec 6, 2005
    #3
  4. Peet

    Peet Guest

    Thanks a lot, Tony, it works! :eek:)

    You wrote:
    "Of course - it's a submit button! "
    I thought button-type button is differs from submit-type button to be
    able to make difference between them... And, with any other browsers,
    the sam page has worked correctly, just Firefox needs this solution.
    But returning false after onclick() has resolved my problem.
    Thanks again :)

    Peter
    Peet, Dec 6, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert V
    Replies:
    1
    Views:
    1,159
    Jeremy Fluhmann
    Jul 21, 2003
  2. Scott M.

    Run JavaScript before Form Submits

    Scott M., Nov 17, 2003, in forum: ASP .Net
    Replies:
    14
    Views:
    7,039
    Joe Gass
    Nov 18, 2003
  3. Stan
    Replies:
    1
    Views:
    2,504
    Jacob Yang [MSFT]
    Dec 3, 2003
  4. CK
    Replies:
    9
    Views:
    382
    Jerry Rasmussen
    Oct 19, 2006
  5. Matthew Sims
    Replies:
    0
    Views:
    127
    Matthew Sims
    Mar 4, 2004
Loading...

Share This Page