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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Yes/No for a form button

Status
Not open for further replies.

ofcalcul

IS-IT--Management
Sep 28, 2004
24
RO
I have a form button in a webpage for deleting records in a database. For this I need the user confirmation like "Are you sure you want to delete the record?" Yes/No.
Can you help me?

 
Use the JavaScript "confirm" function:

Code:
var retVal = window.confirm('Do you want to delete this?');
alert(retVal);

It will return true if "OK" is clicked, false otherwise.

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
addendum:

do not rely solely on javascript for this. if i were you, i'd do another check server-side to make sure the user wants to do this. maybe an in-between page, because if i disable javascript, then click the delete link, i won't be asked if i'm sure.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Can you please give me an entire example? I am a newbie in javascript and don't know how to implement it in the HTML form.
Thank you.
 
This would work:

Code:
<form onsubmit="return(window.confirm('Do you want to delete this?'));">

The form will submit if you click "OK", and not otherwise.

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top