Confirm Javascript

Confirm alert in JavaScript helps to choose two options, either go for further execution of action, or quit the further execution of action. This will ask confirmation from user ARE YOU SURE FOR NEXT EXECUTION OF ACTION. If user press OK button then confirm box return true value.

This true value means go for execution of next work.

Where can we use confirm box, if a form containing records and there is edit or delete action button. User click on edit or delete button by mistakenly, confirm box JavaScript give alert to user to confirm action.
When user click on submit button, a small popup window open and the message written in confirm function will print in popup window, with two button OK and Cancel.

In JavaScript confirm box can implement with confirm function, it will return true if user press on OK button, otherwise it will return false if user press Cancel button.

Demo

<html>
<head>
<title>Confirm javascript</title>
<script>
    function validate()
    {
      var confirmMessage="Are you sure to move Yahoo home page!";

      if(confirm(confirmMessage)==false)
      {
          return false;
      }
    }
</script>
</head>

<body>
    <form name="frm" action="http://yahoo.com" onSubmit="return validate()">
       <input type="submit" name="goSubmit" value="Submit" />
    </form>
</body>
</html>
Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post