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

javascript "OK"/ confirm and "Cancel"/no button? 2

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
hi,
is there an option with alert that user can choose to click "OK"/"yes" or "cancel"/"no" to confirm a delete or similar function?
thanks.
 
Code:
<script>
var blnResponse = confirm("Are you sure you want to delete?");
alert(blnResponse);
</script>

using it with a link

Code:
<script>
funtion confirmDelete() {
return confirm("Are you sure?");
}
</script>

<a href="mypage.html" onclick="return confirmDelete();">delete this</a>


TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
vicvirk,
thanks. so, you use "confirm" instead of alert.
that did it.
 
<script>
funtion confirmDelete()
{
var blnResponse = confirm("Are you sure you want to delete?");
alert(blnResponse);
if (blnResponse == "true")
{
alert("true - OK button was pressed.");
}
if (blnResponse == "false")
{
alert("false - NO button was pressed.");
}
}
</script>
<body>
<a href="mypage.html" onclick="return confirmDelete();">delete this</a>
i'm getting an error:
line 6 where the word function is.
char 9 - ";" is required.
 
Hi

Code:
fun[red]c[/red]tion confirmDelete()
{
  if (confirm("Are you sure you want to delete?"))
  {
    alert("true - OK button was pressed.");
  }
  [red]else[/red]
  {
    alert("false - NO button was pressed.");
  }
}

Feherke.
 
thanks feherke.
that did it.
cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top