Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: I need Cancel Button to be removed from java script confirm/alert box

  1. #1
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default I need Cancel Button to be removed from java script confirm/alert box

    <a href="javascript: if (confirm('Message....')) { window.open('https://www.url.com'); void('') } else { void('') }; "> <strong>Link</strong></a>

    I have the code above that works well. When the user clicks on link a box opens with the message and OK and cancel button. If OK is clicked a new window opens to www.url.com but I need to get rid of the cancel button in the dialogue box. I just want the option to be OK

    I've tried variations of using alert as opposed to confirm but cant seem to get it.
    What am I missing?

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Try this:
    Code:
    <a href="javascript: void(0)" onclick="alert('You will be directed to www.url.com'); window.open('http://www.url.com')"><b>Link</b></a>

  3. The Following User Says Thank You to molendijk For This Useful Post:

    Pat H (08-25-2015)

  4. #3
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by molendijk View Post
    Try this:
    Code:
    <a href="javascript: void(0)" onclick="alert('You will be directed to www.url.com'); window.open('http://www.url.com')"><b>Link</b></a>

    Perfect. Thank you so much. Is there away I can mark this as Correct answer?

  5. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    You can mark it as solved. (But I don't know how to do this).

  6. The Following User Says Thank You to molendijk For This Useful Post:

    Pat H (08-25-2015)

  7. #5
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Client want to use jquery alert instead of javascript

    Quote Originally Posted by molendijk View Post
    You can mark it as solved. (But I don't know how to do this).
    It turns out that my client wants to use jquery alert instead of javascript.
    Is there anything out there that works like the onclick="alert() and window.open?

  8. #6
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    There are many jquey alerts, see http://www.sitepoint.com/10-jquery-a...ndows-prompts/
    So it depends on what kind of alert your client wants.

  9. #7
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Jquery alert

    Quote Originally Posted by molendijk View Post
    There are many jquey alerts, see http://www.sitepoint.com/10-jquery-a...ndows-prompts/
    So it depends on what kind of alert your client wants.
    I guess the issues I see with these jquery alerts is after clicking OK how then do they go to the original link.
    I see how it could probably work if I was going to one link every time but our links are dynamic, meaning there could be 20 different links on one page.
    Also these demos I see always seem to have buttons, where I have hyperlinks that need the alert code.

  10. #8
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    You can tweak the scripts to let them do what you want. But I guess that would be a bit of a problem for you.
    So as soon as I've got some time, I'll create a script for you that you could use for your custom alerts. It may take a while, 'cause I'm very busy right now.

  11. #9
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Quote Originally Posted by Pat H View Post
    <a href="javascript: if (confirm('Message....')) { window.open('https://www.url.com'); void('') } else { void('') }; "> <strong>Link</strong></a>

    I have the code above that works well. When the user clicks on link a box opens with the message and OK and cancel button. If OK is clicked a new window opens to www.url.com but I need to get rid of the cancel button in the dialogue box. I just want the option to be OK

    I've tried variations of using alert as opposed to confirm but cant seem to get it.
    What am I missing?
    I'm struggling to follow the logic here. If you are going to have only one option which is to follow the link, then why do you need the alert box? It makes more sense to just open the link directly in a new tab or window.

  12. #10
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Quote Originally Posted by styxlawyer View Post
    I'm struggling to follow the logic here. If you are going to have only one option which is to follow the link, then why do you need the alert box? It makes more sense to just open the link directly in a new tab or window.
    I understand what you mean, but see the script in my next reply.

Similar Threads

  1. Alert/Confirm box for saving data
    By newphpcoder in forum JavaScript
    Replies: 1
    Last Post: 12-19-2011, 03:18 PM
  2. confirm / alert confilict
    By crobinson42 in forum JavaScript
    Replies: 0
    Last Post: 09-05-2010, 05:34 AM
  3. confirm redirects but alert doesnt
    By vineet in forum JavaScript
    Replies: 1
    Last Post: 07-09-2009, 04:28 PM
  4. Validate with Alert and Confirm
    By fmrock in forum JavaScript
    Replies: 0
    Last Post: 10-01-2007, 02:59 PM
  5. Replies: 23
    Last Post: 07-23-2006, 10:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •