...

View Full Version : confirmation message in JS



husnamina
08-10-2006, 05:29 PM
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--

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 :)

Kor
08-10-2006, 05:53 PM
just this should be enough:


<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">

husnamina
08-10-2006, 06:42 PM
working perfectly mate! thanx :thumbsup:

Kor
08-10-2006, 08:49 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum