Confirm usage in Javascript

Source: Internet
Author: User

Confirm Function

The confirm function is used to provide the confirmation function. It first displays the information contained in the given message parameter, and provides two optional answers: "OK" and "cancel ", then wait for the user to select one of them. If the user selects "OK", true is returned; otherwise, false is returned if "cancel" is selected. The syntax format of this function is as follows:

Window. Confirm (message, OK, cancel)

It has three parameters. The message parameter is a prompt message in the string format to be displayed, and the OK parameter is also a string information to be displayed. It can be "OK ", it can also be other text information that indicates OK, such as "I agree" and "I like". Similarly, the cancel parameter is used to display string information, it can be a "cancel" text or other text information that represents the meaning of cancel.

<SCRIPT>
VaR bln = Window. Confirm ("OK? ");
Alert (BLN)
</SCRIPT>

Or
Button. Attributes. Add ("onclick", "javascript: If (! Confirm ('Are you sure you want to delete this system for consultation? ') {Return false ;}")

Button. Attributes. Add ("onclick", "javascript: Return confirm ('Run after login. Do you want to log on again now? ')")

Example: <a onclick = "javascript: If (! Confirm ('Are you sure you want to delete the selected information? /N this operation cannot be restored! ') {Return false;} "href =" delhtml. asp? ADid = <% = RS ("ADid") %> & type_oneid = <% = RS ("type_oneid ") %> "> <font color =" green "> Delete </font> </a>

Example:

Put the following in

<SCRIPT>

Function rusure ()

{

Question = confirm ("are you sure you want to enter? ")

If (question! = "0 ")

{

Window. Open ("", "test announcement window", "width = 340, Height = 163, toolbar = 0, status = 0, menubar = 0, resize = 0 ");

}

}

</SCRIPT>

Put the following in <body> </body>

<A href = "" onclick = "rusure (); Return false;"> click me </a>

Use confirm to confirm the submission action and submit the confirmation prompt

For example, when you click rewrite in the message book, sometimes we want a prompt to avoid mistakes. The Code is as follows:
  
Method 1

<Input name = "Submit" type = "Submit" onclick = "If (confirm ('Open webpage? ') Location = 'HTTP: // www.05376.com' "value =" open ">

Method 2

<Input name = "reset" type = "reset" onclick = "Return clearbutton ()" value = "Override">
<SCRIPT type = "text/JavaScript">
Function clearbutton ()
{
If (! Confirm ("are you sure you want to rewrite it? ") Return false;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.