SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist spinmaster's Avatar
    Join Date
    Mar 2005
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onClick event handler prevents PHP script from beeing processed? :-(

    Hi,

    I want to show a simple animated (loading) icon when a user pressed on the submit button/submitted the form. A PHP script is then executed and processes some data until it returns a status message.

    However, the PHP script is not executed when I put my JavaScript in the submit button tag:

    PHP Code:
    <form enctype="multipart/form-data" method="POST" action="action_upload.php">

    ...

    <
    input name="submit" onClick="showDiv('loadingDiv'); return false;" type="image" src="button.gif"
    My script in the action tag of the form is then not executed, although showing the loading icon works. When I take out the onClick event handler, the PHP script is called, but why does the onClick handler prevent the PHP script in the action attribute from being called/processed?

    can anyone help me out here pls?? thx!!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    return

    Maybe return true instead of return false?

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague is correct. In many browsers returning false form the onclick handler of a submit button will stop a form from submitting.

    It's better to use the form's onsubmit handler instead of the submit button's onclick handler.

    It's best to avoid using inline event handlers. I suggest you read up on Unobtrusive JavaScript and other JavaScript Best Practices.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Evangelist spinmaster's Avatar
    Join Date
    Mar 2005
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys!!


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
  •