View Full Version : How can I make a "YES & NO" prompt box?
just_me
02-11-2006, 01:19 PM
I have this link:
<a href="/delete/article/321/">Delete Article</a>
When I click that link I want a prompt box asking me if I really want to delete it.
Do you really want to delete that article?
[YES] [NO]
How can I accomplish something like that?
THANKS!
shyam
02-11-2006, 01:40 PM
with the standard confirm() function you can't...but if u are adventurous u can try ur hand at crafting one of your own with some DHTML alchemy :)
just_me
02-11-2006, 03:29 PM
Thanks for the reply! I'm using confirm() now...
beastyboy
02-11-2006, 08:45 PM
it can be done in the following way:
<html>
<head>
<title>confirm before delete</title>
<script language="JavaScript" type="text/javascript">
<!--
function confirmDelete() {
if (confirm("Really delete this article?")) {
return true;
} else {
return false;
}
}
//-->
</script>
</head>
<body>
<form id="form1" name="form1">
<h3>List of articles</h3>
<table border=1 cellpadding=3>
<tr>
<td>article 321</td>
<td><a href="/delete/article/321/" onClick="return confirmDelete();">delete this article</a></td>
</tr>
<tr>
<td>article 322</td>
<td><a href="/delete/article/322/" onClick="return confirmDelete();">delete this article</a></td>
</tr>
</table>
</form>
</body>
</html>
beastyboy
02-11-2006, 09:32 PM
Of course this does not give a "yes/no" box but a default "ok/cancel", so for that it's not a proper solution. Probably you already figured that out ;)
Cheers
felgall
02-11-2006, 10:02 PM
Why use a whole lot of code:
function confirmDelete() {
if (confirm("Really delete this article?")) {
return true;
} else {
return false;
}
when one line will do it:
function confirmDelete() {return confirm("Really delete this article?")}
if so, why not?:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
onload=function(){
var a = document.getElementsByTagName('table')[0].getElementsByTagName('a');
for(var i=0;i<a.length;i++){a[i].onclick=function(){return confirm('Really delete this article?')}}
}
</script>
</head>
<body>
<form id="form1" name="form1">
<h3>List of articles</h3>
<table border=1 cellpadding=3>
<tr>
<td>article 321</td>
<td><a href="/delete/article/321/">delete this article</a></td>
</tr>
<tr>
<td>article 322</td>
<td><a href="/delete/article/322/">delete this article</a></td>
</tr>
</table>
</form>
</body>
</html>
vwphillips
02-11-2006, 10:39 PM
http://www.js-examples.com/forums/viewtopic.php?t=951&highlight=promptconfirmalert
An IE only VBS alternative
<script type="text/javascript" language="javascript">
function iniMsgBox(){
window.confirm=function(msgStr){
return vb_confirm(msgStr)
}
}
</script>
<script type="text/vbs" language="vbscript">
iniMsgBox()
Function vb_confirm(msgStr)
vb_confirm = MsgBox(msgStr, vbYesNo + vbQuestion + vbDefaultButton1 + vbApplicationModal, document.title) = vbYes
End Function
</script>
<script type="text/javascript" language="javascript">
alert(confirm('take this action?'));
</script>
felgall
02-12-2006, 08:45 PM
The problem with using VB is that the only time you can guarantee it will run is on an intranet where you know that everyone is using IE. On the internet the number of people using IE is falling (on my own site its now under 70%).
The problem with using VB is that the only time you can guarantee it will run is on an intranet where you know that everyone is using IE. On the internet the number of people using IE is falling (on my own site its now under 70%).
There are no guarantees in internet scripting, in any language. The only time you can guarantee that JS will run is also in a controlled environment.
The only problem I can think of in using MsgBox online is if the actual button text is part of the page functionality. Otherwise, I see no reason not to exploit some of its features (http://msdn.microsoft.com/library/en-us/script56/html/517be4ea-7c55-4780-a48d-0b0224b29315.asp). It would be worth using if the number of IE users were at 25%
http://www.thecounter.com/stats/2006/February/browser.php
felgall
02-13-2006, 08:57 PM
If 10% of users have active scripting disabled and 100% of browsers support Javascript then 90% will see whatever the Javascript does. With only 70% of browsers supporting VB only 63% (less than 2/3) of visitors will see what that does.
Not saying you shouldn't use either, just pointing out what percentage of your visitors might not see it.
But the vbs example was written very slickly where confirm() is only modified to utilize vbs IF there is VBscripting available. I see no harm at all in using that example. :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.