473,473 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

confirm() function doesn't seem to work

I have a confirm alert before the user goes to a delete page, and it
doesn't matter if the user clicks ok or cancel - they always go to the
delete page.

I have the following code:

<a href="vehicle_history_delete.php?history_id=18&veh icle_id=5"
onclick="return DelAlert();"><img border=0
src="/images/delete_category_16.gif" alt="Delete This record"
title="Delete this record">

Where DelAlert() looks like:

<script language="JavaScript" >

function DelAlert() {
if (confirm("Are you sure you want to delete this history record?"))
{
return true;
} else
{
alert('Should be false');
return false;
}
}

</script>

And have tried

<a href="vehicle_history_delete.php?history_id=10&veh icle_id=5"
onclick="return confirm('Are you sure you want to delete?')">
<img border=0 src="/images/delete_category_16.gif" alt="Delete This
record" title="Delete this record">
</a>

as well.

This DOES prevent the navigation to the delete page:

<a href="vehicle_history_delete.php?history_id=10&veh icle_id=5"
onclick="return false;">

But is obviously not acceptable.

Here's the kicker. The same code on a different page works fine. This
page does not work in either IE or Firefox.

Ever happen to anybody before?

Eric

Sep 29 '06 #1
8 14616
Lee
Eric said:
>
I have a confirm alert before the user goes to a delete page, and it
doesn't matter if the user clicks ok or cancel - they always go to the
delete page.

I have the following code:

<a href="vehicle_history_delete.php?history_id=18&veh icle_id=5"
onclick="return DelAlert();"><img border=0
src="/images/delete_category_16.gif" alt="Delete This record"
title="Delete this record">

Where DelAlert() looks like:

<script language="JavaScript" >

function DelAlert() {
if (confirm("Are you sure you want to delete this history record?"))
{
return true;
} else
{
alert('Should be false');
return false;
}
}

</script>

And have tried

<a href="vehicle_history_delete.php?history_id=10&veh icle_id=5"
onclick="return confirm('Are you sure you want to delete?')">
<img border=0 src="/images/delete_category_16.gif" alt="Delete This
record" title="Delete this record">
</a>

as well.

This DOES prevent the navigation to the delete page:

<a href="vehicle_history_delete.php?history_id=10&veh icle_id=5"
onclick="return false;">

But is obviously not acceptable.

Here's the kicker. The same code on a different page works fine. This
page does not work in either IE or Firefox.
The code you posted works fine.
There's something else in your page that's clobbering it.
Have you defined a "confirm()" function that's replacing the built-in?
--

Sep 29 '06 #2
>
The code you posted works fine.
There's something else in your page that's clobbering it.
Have you defined a "confirm()" function that's replacing the built-in?
Nope. It was a good thought, so I checked, but if I did I wouldn't
even see the message - which I do.

E

Sep 29 '06 #3
JRS: In article <11*********************@h48g2000cwc.googlegroups. com>,
dated Fri, 29 Sep 2006 12:34:31 remote, seen in
news:comp.lang.javascript, Eric <er**@bangsoftworks.caposted :
>
function DelAlert() {
if (confirm("Are you sure you want to delete this history record?"))
{
return true;
} else
{
alert('Should be false');
return false;
}
}
(1) There is no need for an else part if the previous code returns.
(2) The following is simpler :-

function DelAlert() { var OK
OK = confirm("Are you sure you want to delete this history record?")
if (!OK) alert('Should be false')
return OK }

It's a good idea to read the newsgroup and its FAQ. See below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 30 '06 #4
Dr John Stockton wrote on 30 Sep 2006 in comp.lang.javascript:
function DelAlert() { var OK
OK = confirm("Are you sure you want to delete this history record?")
if (!OK) alert('Should be false')
return OK }
function DelAlert() {
if (confirm("Are you sure you want to delete this history record?")){
alert('Should be false');
return false;
};
// return true; // unneccessary?
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 30 '06 #5
On 2006-09-30 20:48:11 +0200, "Evertjan." <ex**************@interxnl.netsaid:
function DelAlert() {
if (confirm("Are you sure you want to delete this history record?")){
alert('Should be false');
return false;
};
// return true; // unneccessary?
}
That would return false when the dialog is confirmed.

Anyway the alert() line is obviously a temporary debug line. The
function could be further simplified as :

function DelAlert() {
return confirm("Are you sure you want to delete this history record?")
}

at which point it may be just as well to inline it.

I'm not sure why it doesn't work, but you could work around the problem
by using the function to change the document.URL instead of cancelling
the navigation, and instead of a link, use a button, or an input
type="image". Links aren't supposed to perform actions like deleting
something anyway.
--
David Junger

Sep 30 '06 #6
Touffy wrote on 01 Oct 2006 in comp.lang.javascript:
On 2006-09-30 20:48:11 +0200, "Evertjan."
<ex**************@interxnl.netsaid:
>function DelAlert() {
if (confirm("Are you sure you want to delete this history
record?")){
alert('Should be false');
return false;
};
// return true; // unneccessary?
}

That would return false when the dialog is confirmed.

Anyway the alert() line is obviously a temporary debug line. The
function could be further simplified as :

function DelAlert() {
return confirm("Are you sure you want to delete this history
record?")
}

at which point it may be just as well to inline it.

I'm not sure why it doesn't work,
What does not work?
but you could work around the
problem by using the function to change the document.URL instead of
cancelling the navigation, and instead of a link, use a button, or an
input type="image". Links aren't supposed to perform actions like
deleting something anyway.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 30 '06 #7

Evertjan. wrote:
Touffy wrote on 01 Oct 2006 in comp.lang.javascript:
Anyway the alert() line is obviously a temporary debug line. The
function could be further simplified as :

function DelAlert() {
return confirm("Are you sure you want to delete this history
record?")
}

at which point it may be just as well to inline it.

I'm not sure why it doesn't work,

What does not work?
The confirm(). It doesn't prevent navigation to the delete page. It
doesn't work inline or if I put it in another function. That is why I
posted the original question.

I will take David Junger's (good) advice though and change the pages to
not use a hyperlink for the delete. (He was right about the alert being
a temporary debugging thing too) I will use an input type=image and
see how that works. (A button won't look right, which is why I used a
hyperlink in the first place)

Eric

Sep 30 '06 #8
Eric wrote on 01 Oct 2006 in comp.lang.javascript:
Evertjan. wrote:
[..]
function DelAlert() {
return confirm("Are you sure you want to delete this history
record?")
}
I'm not sure why it doesn't work,

What does not work?

The confirm(). It doesn't prevent navigation to the delete page. It
doesn't work inline or if I put it in another function. That is why I
posted the original question.
Well let's go back to basics:

============= test.html ===============
<a
href="vehicle_history_delete.php?history_id=18&veh icle_id=5"
onclick="return DelAlert();">
click me [instead of the img]</a>

<script type='text/javascript'>
function DelAlert() {
return confirm("Are you sure you want to delete?")
}
</script>
========================================

The above .html works fine, just try it,
so you must have [made?] an error elsewhere in your code.
[..]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 1 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Logger | last post by:
Help, I’m trying to implement a confirm button on an asp.net page. I have it attached to a asp:button control. In the button1 click event I call the CreateConfirmBox subroutine. The Box comes...
2
by: Terry | last post by:
anyone know how to pop up a confirm window with (Y) & (N)?? I want to pop up a "Do you want to continue?" message box (javascript only, can't use vbscript) with (Y) & (N). when click (N), then...
3
by: Doug O'Leary | last post by:
Hey, all; Apparently, I'm missing the concept. I'm writing a web app in perl to manage nagios configuration files. One of the things I'd like to do is to confirm an update via a popup window...
1
by: Sandy | last post by:
I have a repeater which shows Group names. (Skip this part if you want rather irrelevant) The groups are ordered and formatted: Parent ---Child ------Grand Child (okay start reading again...
8
by: Dave | last post by:
Hello all, I have been able to use a Javascript alert box in my vb.net web application, for example: Dim msg As String = "Hello, world." Dim alertScript As String = "<script...
3
by: enzo | last post by:
I'm using asp.net 2.0 I have a checkbox with server checkedCanged event . I must add a confirm on click event. I have used this : myCheckBox.Attributes.Add("onClick", "return...
4
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit"...
2
by: dddan | last post by:
Here's my code: <asp:LinkButton OnClick="DeleteFile" OnClientClick="if (!confirm ('Are you certain you want to delete this file?') ) return false;" runat="server" ID="DeleteButton">DELETE...
3
by: atiger | last post by:
I am doing some validation in an ascx page. I have two textboxes. if user types char in the box, an alert box will be displayed, if user doesn't enter anything, a confirm box need to be displayed....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.