Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirm on Submit 1

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
When I press the submit button it has ok or cancel. When I hit ok it submits the data, when I hit cancel it submits the data. I want it when I hit cancel to not submit the data or reload the page. Here's my code:

<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
msg = "Are you sure all the information entered is correct?";
return confirm(msg);
}
</SCRIPT>


<input type="submit" name="Submit" value="Submit Payment" onClick="verify()">
 
You need to check to determine if the user is clicking yes or no, not simply returning the confirm function. Some slight modifications are necessary.
Code:
<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
    msg = "Are you sure all the information entered is correct?";
    if(confirm(msg))
    {  return true;
    }
    else
    {  return false;
    }
}
</SCRIPT>


<input type="submit" name="Submit" value="Submit Payment"  onClick="return verify()">
By returning true or false, it will correspondingly submit or not submit the form.

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
The simplest way is

<input type=submit onclick="return confirm('Sure?')">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top