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.')";
scriptString += "</script>";
Response.Write(scriptString);
Is there a way to determine if you select yes or no?
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.')";
scriptString += "</script>";
Response.Write(scriptString);
Is there a way to determine if you select yes or no?
Share Improve this question edited Feb 8, 2011 at 23:29 jcolebrand 16k12 gold badges77 silver badges122 bronze badges asked Feb 8, 2011 at 23:10 user175084user175084 4,64028 gold badges119 silver badges170 bronze badges 1- I think you really really need to clarify. Where do you want to know if they said yes or no? On the server or only in the javascript? – jcolebrand Commented Feb 8, 2011 at 23:28
3 Answers
Reset to default 1var 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/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#