Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Alert Yes or No

  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alert Yes or No

    I am calling the function from a button using onclick. Is it possible to have the alert popup with a yes and no button. The yes lets it continue and no returns false.

    Basically what is happening is a user fills in the forms that have no required info, but I want to ask the user if they are really ready to sumbit just incase they hit the enter button instead of the tab button.


    <SCRIPT language=JavaScript>
    function checkCheckBox(){

    alert("Do you want to submit")
    if(confirm("")) {
    contine#####
    }
    else
    return false;
    }
    </SCRIPT>

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    the following should do you want. be aware, however, that you'll get 'Ok' and 'Cancel' for your buttons, instead of 'Yes' and 'No', and there's no way to change that.

    function checkCheckBox(){
    return confirm("Do you want to submit");
    }
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    forget the alert()...

    The confirm() gives you OK / Cancel buttons that return true and false respectively.

    function confirmAction() {
    return confirm ("Are you suuuurrreeee?");
    }

    use it in your <form> tag, thus:

    <form .... onSubmit="return confirmAction()">

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Another approach is to disable the enter key:-

    function onKeyPress () {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {
    alert ("Please use the tab key (not the enter key) or click\nwith your mouse to move between the form fields.");
    return false
    }
    return true
    }
    document.onkeypress = onKeyPress;


  •  

    Posting Permissions

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