Web Analytics Made Easy -
StatCounter Alert Yes or No - CodingForum


No announcement yet.

Alert Yes or No

  • Filter
  • Time
  • Show
Clear All
new 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("")) {
    return false;
    If you don't do it this year, you will be one year older when you do. "Warren Miller"

  • #2
    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
      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
        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;

        All the code given in this post has been tested and is intended to address the question asked.
        Unless stated otherwise it is not just a demonstration.