SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict reboltutorial's Avatar
    Join Date
    Jan 2009
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Why onclick doesn't work on submit button ?

    Sorry it's a long time I programmed in Js, I come back to it now for my hobby site. I added a submit button with an onclick event and an alert message to say it doesn't work yet, but if I push the button, it isn't taken into account and the form is submitted to the cgi.

    What's wrong ?
    Code:
    <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" onclick="alert('Sorry, it's not working yet!');return false;" >

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2009
    Location
    Ottawa, Ontario, Canada
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Somewhere in your JS you will need something like:

    document.forms[X].onsubmit = validateBeforeSubmit;

    where "X" indicates the form where the submit button is located and "validateBeforeSubmit" is a function you create.

    If validateBeforeSubmit returns "true" then the submit function will be treated normally. If it returns "false" it won't.

    That should do it...

    floater

  3. #3
    SitePoint Addict reboltutorial's Avatar
    Join Date
    Jan 2009
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but finally I found it, I didn't escape the "'"


Bookmarks

Posting Permissions

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