confirm() function doesn't seem to work

Discussion in 'Javascript' started by Eric, Sep 29, 2006.

  1. Eric

    Eric Guest

    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&vehicle_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&vehicle_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&vehicle_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
    Eric, Sep 29, 2006
    #1
    1. Advertising

  2. Eric

    Lee Guest

    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&vehicle_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&vehicle_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&vehicle_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?


    --
    Lee, Sep 29, 2006
    #2
    1. Advertising

  3. Eric

    Eric Guest

    >
    > 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
    Eric, Sep 29, 2006
    #3
  4. JRS: In article <>,
    dated Fri, 29 Sep 2006 12:34:31 remote, seen in
    news:comp.lang.javascript, Eric <> posted :
    >
    >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.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Sep 30, 2006
    #4
  5. Eric

    Evertjan. Guest

    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)
    Evertjan., Sep 30, 2006
    #5
  6. Eric

    Touffy Guest

    On 2006-09-30 20:48:11 +0200, "Evertjan." <> said:

    > 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
    Touffy, Sep 30, 2006
    #6
  7. Eric

    Evertjan. Guest

    Touffy wrote on 01 Oct 2006 in comp.lang.javascript:

    > On 2006-09-30 20:48:11 +0200, "Evertjan."
    > <> said:
    >
    >> 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)
    Evertjan., Sep 30, 2006
    #7
  8. Eric

    Eric Guest

    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
    Eric, Oct 1, 2006
    #8
  9. Eric

    Evertjan. Guest

    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&vehicle_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)
    Evertjan., Oct 1, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bill Green

    &nbsp; in a ListItem doesn't seem to work

    Bill Green, Feb 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    405
    vMike
    Feb 7, 2004
  2. Garrett
    Replies:
    4
    Views:
    4,775
    Garrett
    Dec 2, 2004
  3. tshad
    Replies:
    3
    Views:
    496
    MWells
    Jan 26, 2005
  4. Wiseguy
    Replies:
    2
    Views:
    317
    Jonathan Turkanis
    Jan 18, 2004
  5. dphizler
    Replies:
    1
    Views:
    77
    dphizler
    Apr 14, 2010
Loading...

Share This Page