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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question confirmation message in JS

    hi
    been trying to code in php and am glad to say this forum has been a great help, but now i want to do something in JS.

    I want to have a confirm message to be shown when the submit button is pressed

    ok --to go and post in to darabase
    cancel-- to just remain on that page without posting, so user can edit input 1st before posting.

    but when I click cancel it still posts

    here is my code
    --JS function--
    Code:
    function doConfirm(){
    
    answer = confirm("Please Confirm your post, you will not be able to edit after posting")
    
    if (answer !="0") 
    { 
    location = "reply_from2.php" 
    } 
    }
    and the function is called on the onclick attribute of the submit button
    thanks

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    just this should be enough:
    Code:
    <form action="reply_from2.php" method="get" onsubmit="return confirm('Please Confirm your post, you will not be able to edit after posting')">
    ...
    <input type="submit" name="sub" value="Submit">
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    working perfectly mate! thanx

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    you see, this kind of validation functions in a form are to be triggered rather by the onsubmit event, not by onclick, as the return true/false should allow/prevent the HTML action, or the onclick could maybe prevent a "href" action, but not a submit one, as the submit action belongs to the form element, not to the submit button.
    Last edited by Kor; 08-10-2006 at 07:51 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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