Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    <form onsubmit = "javascript" ..

    This works, onsubmit triggers

    Code:
    <form ..    onsubmit="alert('a'); >
      <input type ="submit" value ="submit"  />
    This does not, onsubmit does not trigger

    Code:
    <form ..    onsubmit="alert('a'); >
      <img onclick = "document.getElementById('commentsForm').submit();" />
    Should second case work or not ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    No, it should not work.

    When you call the submit() function, you are *NOT* triggering an EVENT.

    The function submit() is *INTERNALLY CALLED* by onsubmit when the onsubmit event handler returns true.

    Do not confuse the event with the built-in function.

    NOTE: An easy way to get around this is to use:
    Code:
    <form ..    onsubmit="alert('a');" >
      <input type="image" src="..."/>
    </form>
    or you can do
    Code:
    <form ..    onsubmit="alert('a');" >
      <button type="submit"><image" src="..."/></button>
    </form>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    BubikolRamios (08-29-2013)

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The best solution is to not jumble the HTML and JavaScript in the first place but to keep them in separate files instead.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •