Javascript Yes/No

Discussion in 'ASP General' started by Fawke101, May 13, 2004.

  1. Fawke101

    Fawke101 Guest

    Hi there,

    I have searched for some examples, but to no real avail, for a JS function
    that displays a user Yes/No dialog box.
    Basically, i have an ASP application that displays a SQL table on an ASP
    page.

    I have created a "Remove" hyperlink (in a loop) by each record and i need to
    use an OnClick event so when the user clicks this hyperlink it displays this
    Yes/No dialog.
    At the moment the hyperlink simply removes the relevant record.

    I need an OnClick event that displays a Yes/No box that when the user clicks
    Yes - it goes to remove.asp, and when No is clicked it does nothing.

    User Clicks Remove next to record > Yes/No dialog> Yes = remove.asp No =
    End.

    *****
    *****
    Current Hyperlink (passing ID variable in querystring - needs to be
    maintained through the JavaScript:

    <a href="remove.asp?ID=<% =server.URLEncode(RS("ID"))%>">Remove</a>
    *****
    *****

    Any code/help would be much appreciated.
    Thanks

    --
    Thanks in advance

    Fawke

    Please remove ANTI and SPAM
    from my email address before emailing me.

    www.bradflack.com
     
    Fawke101, May 13, 2004
    #1
    1. Advertisements

  2. Fawke101

    Randy Webb Guest

    <a href="#" onclick="customConfirm('remove.asp?ID=<%
    =server.URLEncode(RS("ID"))%>');return false">Remove</a>

    customConfirm would be a function that accepts the URL as a parameter,
    then shows a DIV in the center of the screen with two buttons. The
    buttons would have onclicks that when clicked, would either do nothing
    (the NO button) or set location.href to the remove.asp page.
     
    Randy Webb, May 13, 2004
    #2
    1. Advertisements

  3. Fawke101

    Fawke101 Guest

    Thanks for your prompt reply......
    Sorry to be a pain, i am no JS developer, Any examples of this?

    Thanks so much


    --
    Thanks in advance

    Fawke

    Please remove ANTI and SPAM
    from my email address before emailing me.

    www.bradflack.com
     
    Fawke101, May 13, 2004
    #3
  4. Fawke101

    Saint Jude Guest

    Would a confirm dialog be OK ?
    You can't chnage the button text, but the meaning is clear.

    if(confirm("You want this ?"))
    alert("yes")
    else
    alert("No")
     
    Saint Jude, May 13, 2004
    #4
  5. Fawke101

    TomB Guest

    <a href="remove.asp?ID=<% =server.URLEncode(RS("ID"))%>"
    onClick="confirm('Are you sure?');">Remove</a>

    It's not really an ASP question.
     
    TomB, May 13, 2004
    #5
  6. Fawke101

    Fawke101 Guest

    A confirm would be fine.......

    I just wouldnt mind knowing how to incorporate this into my ASP -

    Do you want this?
    Yes -goto remove.asp
    No - -*nothing*

    How can i incorporate this JS into my code (sorry, i am not clued up with
    JS at all)

    --
    Thanks in advance

    Fawke

    Please remove ANTI and SPAM
    from my email address before emailing me.

    www.bradflack.com
     
    Fawke101, May 13, 2004
    #6
  7. Fawke101

    Randy Webb Guest

    <a href="URL" onclick="return confirm('Are you sure you want to remove
    this item?')">Remove</a>

    If they click OK, it returns True and the link is navigated to. If they
    click cancel, the confirm returns false and the href is not followed.
     
    Randy Webb, May 13, 2004
    #7
  8. Fawke101

    Fawke101 Guest

    Perfect! Big Thanks!

    --
    Thanks in advance

    Fawke

    Please remove ANTI and SPAM
    from my email address before emailing me.

    www.bradflack.com
     
    Fawke101, May 13, 2004
    #8
  9. Shouldn't that be this?

    ...onclick="return confirm('Are you sure?')"...
    ^^^^^^^



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, May 13, 2004
    #9
  10. Fawke101

    Randy Webb Guest

    Yes, it should be. Otherwise its pointless to have it.
     
    Randy Webb, May 13, 2004
    #10
  11. Fawke101

    TomB Guest

    Oops

     
    TomB, May 14, 2004
    #11
  12. That's the point of returning a value -- to avoid the very problem you are
    experiencing. Please review the above carefully.

    If you would like something a bit more enlightening than formulaic, try the
    following:

    <A HREF="" ONCLICK="return false">Click here</A>

    Observe its behavior. Now modify it slightly:

    <A HREF="" ONCLICK="confirm('Really?');return false">Click here</A>

    Again, observe the behavior. Last of all, go back to the structure of my
    original suggestion, and see what it does:

    <A HREF="" ONCLICK="return confirm('Really?')">Click here</A>

    Now you should understand what you are doing wrong.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Jun 9, 2004
    #12
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.