By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

confirm() function doesn't seem to work

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
>
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.