www.webdeveloper.com
Results 1 to 4 of 4

Thread: Submit form without using onSubmit() and 'return false;'

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Question Submit form without using onSubmit() and 'return false;'

    I've read thats the old wrong way of doing things. I'm not using jQuery either. This wont work though

    Code:
    <html>
    <body>
    <form name="contact" id="form_contact" action="" method="post">
    <input type="text" name="form_text" id="form_text" value="">
    <button type="submit" name="form_submit" id="form_submit" value="Go">Go</button>
    </form>
    <script>document.getElementById('form_contact').addEventListener('submit', bling, false);
    
    function bling() {
    alert('submitted');
    stop_event('submit');
    return false;//last resort, not really wanting to use this
    }
    
    
    function stop_event(ev) {
        if (ev.stopPropagation) {
            ev.stopPropagation();
        }
        else {
            ev.cancelBubble = true;
        }
    
        if (ev.preventDefault) {
            ev.preventDefault();
        }
        else {
            ev.returnValue = false;
        }
    }</script>
    </body>
    </html>
    http://jsfiddle.net/PG67k/

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Or, rather than to use jQuery without understanding anything, read, for example, this pages...

  4. #4
    thanks for sharing this information

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles