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!

Need help with an alert box

Status
Not open for further replies.

Linkan

Programmer
Feb 7, 2001
44
SE
I am using a sql 2000 db from where I use data in my asp application. When I delete a record I would like a confirmation alert to pop up where I can cancel or ok my acction.
Can someone give me some hints in this matter.
Thanks for a great forum.
Jonas
 
You can use the javascript function, confirm():

From DevGuru:

confirm("message")

This method brings up a dialog box that prompts the user to select either 'o.k.' or 'cancel', the first returning true and the latter, false.

The following example opens a new window, creates a button in the original window and assigns the closeWindow() function to its onClick event handler. This function prompts the user to confirm the closing of the new window.

Code:
<form action=&quot;&quot; method=&quot;POST&quot; id=&quot;myForm&quot;>
<input type=&quot;Button&quot; name=&quot;&quot; value=&quot;Close&quot; id=&quot;myButton&quot; onClick=&quot;closeWindow()&quot;>

<script type=&quot;&quot; language=&quot;JavaScript&quot;>

myWindow = window.open(&quot;&quot;, &quot;tinyWindow&quot;, 'toolbar, width=150, height=100')

function closeWindow() {
       myWindow.document.write(&quot;Click 'O.K'. to close me and 'Cancel' to leave me open.&quot;)
       


if (confirm(&quot;Are you sure you want to close this window?&quot;)) {


              myWindow.close()
       }
}

</script>
</form>
hope it helps! :)
Paul Prewett
penny.gif
penny.gif
 
Paul,

Thanks this will do the trick.
Linkan
 
Hi Jonas,

You can use a link with the attribute onclick to call the asp-page that delete the record like:

<a onclick=&quot;&quot;{return(window.confirm('Are you sure...?'));}&quot;&quot; href=&quot;deleterecord.asp?RecordID=recordnumber&quot;>linkname</a>

Hope this helps,

Erik
 
Thanks Erik another one I can use.
 
I made to quickly a copy out of my source with double &quot;&quot;, but I think you should use this single &quot;

<a onclick=&quot;{return(window.confirm('Are you sure...?'));}&quot;

Erik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top