I have the following script to ask the user to confirm clicking a button depending on a system setting.
The system setting is stored in a hidden field set from code behind.
Markup:
<asp:HiddenField ID="hfConfirmOnApproval" runat="server" Value="False" />
cs:
//Read the confirm on approval setting
hfConfirmOnApproval.Value = Objects.Engine.Settings.Instance.ConfirmOnApproval.ToString();
js:
//Get whether to confirm on approval
var _confirmOnApproval = new Boolean($('#hfConfirmOnApproval').val());
if ( _confirmOnApproval ? confirm('Are you sure you want to approve this item?') : true )
{
// do work
}
The problem is that the confirm message box is being displayed even though _confirmOnApproval is set to false?
I only want the message box to appear if its set to true.
The _ConfirmOnApproval is false at the moment
SOLUTION:
js:
var _confirmOnApproval = $('#<%=hfConfirmOnApproval.ClientID %>').val() == "True" ? true : false;
if ( _confirmOnApproval ? confirm('Are you sure you want to approve this item?') : true ) {
//Do work
}
It’s because you’ve used
new Booleanto create a Boolean object, andtypeof _confirmOnApprovalwill return “Object”:You could get rid of
new Booleanand just compare the value: