[Webinar] Learn how to a build a cloud-first strategyRegister Now


Stop a submit with javascript...

Posted on 2006-05-02
Medium Priority
Last Modified: 2008-01-09
I have a form in PHP that will submit $_POST to a script for processing.  Right now I have a confirmation box (javascript) that pops up when the 'submit' button is clicked asking 'Are you sure?', but either way the form gets processed . . . How can I stop the form from being processed if the user clicks 'Cancel'.

<form method='post' action='./somefile.php'>

....form inputs....
<input type='submit' onClick='confirmSubmit()' />

function confirmSubmit(){
if(confirm('Are you sure?')){
return true;
} else { return false;}

I suck.
Question by:mynamebecory2

Expert Comment

ID: 16585303
You are so close to getting it! You need to add the validation as a onSubmit action for your form, rather than as a button action.

<form method='post' action='./somefile.php' onSubmit="return confirmSubmit(this)'>

....form inputs....
<input type='submit'/>

Accepted Solution

jim_spath earned 120 total points
ID: 16587708
An even simpler way to do it would be:

<form method='post' action='./somefile.php' onSubmit="return confirm('Are you sure?');">

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question