开发者

Get value from confirm box

开发者 https://www.devze.com 2023-02-09 15:18 出处:网络
How do I get the value of the confirm box selected: I have this code: string scriptString = \"<script language=\'JavaScript\'> \";

How do I get the value of the confirm box selected:

I have this code:

string scriptString = "<script language='JavaScript'> ";
scriptString += "confirm ('Are you sure you want to Close this period.')"开发者_C百科;
scriptString += "</script>";
Response.Write(scriptString);

Is there a way to determine if you select yes or no?


var x = confirm('...')
alert(x)

or

string scriptString = "<script language='JavaScript'> ";
scriptString += "var x = confirm ('Are you sure you want to Close this period.')";
scriptString += "alert(x)";            
scriptString += "</script>";
Response.Write(scriptString);


Confirm returns a boolean value indicating ok or cancel (true means ok, false means cancel).

You can use it like this:

if(confirm ('Are you sure you want to Close this period.')) {
  //they clicked ok
}
else {
  //they clicked cancel
}

read more about it here: https://developer.mozilla.org/En/DOM/Window.confirm


You should store the result of the confirm in a hidden field value like this:

if (confirm("Are you sure you want to proceed?")==true){
    hiddenField.value = 'true';
    return true;
} else {
    hiddenField.value = 'false';
    return false;
}

and then fetch the value of the hidden field from C#

0

精彩评论

暂无评论...
验证码 换一张
取 消