Prompting the user

There are three functions you can call which will force the user to acknowledge them. These are

  • alert()
  • confirm()
  • prompt()

alert()

If you would like to present the user with a notice before allowing them to continue using your web page, you can display an alert.

<a href="javascript:alert('Hello, World!'">See Demo</a>

<script language="javascript">
<!--
  alert("Hello, World!");
-->
</script>

confirm()

To prompt the user with a Yes/No message box you can call confirm, using its return value as the result.

<script language="javascript">
<!--
  var result = confirm("Are you sure?");

  if (result)
    alert("You clicked OK");
  else
    alert("You clicked cancel");
-->
</script>

prompt()

xxx

<script language="javascript">
<!--
  var name = prompt("What is your name?","Mickey Mouse");

  alert(name);
-->
</script>
Author Barrington Haynes

I have nothing more to say

Add Comment

Name
Comment
 

Your comment has been received and will be shown once it passes moderation.