I've been struggling to make this particular JavaScript function work, but so far I haven't had any success.
Every time I try to call the confirm dialog, I keep receiving an error saying "function expected."
Could someone please point out what mistake I might be making?
In essence, what I'm trying to do in my code is check if the form validators are set to fire. Then, I extract the values from two ASP.NET radio button lists and check if items have been selected from two checkbox lists.
If there's at least one item selected in the checkboxes and either of the radio button lists is set to 'yes,' then I want to trigger the confirm dialog.
function FormSubmissionConfirm() {
if (Page_ClientValidate()) {
// Get all the relevant form values
var showConfirm = false;
var storage = document.getElementsByName("<%: StorageRBL.UniqueID%>");
var storageAnswer;
for (var j = 0; j < storage.length; j++) {
if (storage[j].checked) {
storageAnswer = storage[j].value;
}
}
var flat = document.getElementsByName("<%: FlatRBL.UniqueID%>");
var flatAnswer;
for (var j = 0; j < flat.length; j++) {
if (flat[j].checked) {
flatAnswer = flat[j].value;
}
}
var confirm = document.getElementById("<%: preferedlist.ClientID%>");
var confirmChkBoxCount = confirm.getElementsByTagName("input");
var confirmAnswer;
for (var i = 0; i < confirmChkBoxCount.length; i++) {
if (confirmChkBoxCount[i].checked)
confirmAnswer = true;
}
var reminder = document.getElementById("<%: reminderList.ClientID%>");
var chkBoxCount = reminder.getElementsByTagName("input");
var reminderAnswer;
for (var i = 0; i < chkBoxCount.length; i++) {
if (chkBoxCount[i].checked)
reminderAnswer = true;
}
if (reminderAnswer ==true && confirmAnswer == true) {
if (storageAnswer == "yes" || flatAnswer == "yes") {
showConfirm = true;
}
}
if (showConfirm)
return confirm("Please confirm that the details entered are correct");
else
return true;
}
else {
return true;
}
}
This is the button markup.
<asp:Button runat="server" Text="Confirm" CssClass="btn btn-lg btn-primary pull-right" ID="ConfirmBtn" OnClientClick="if (! FormSubmissionConfirm()) return false;" OnClick="ConfirmBtn_Click" CausesValidation="True" />
Any assistance with this would be greatly appreciated.
Thank you, Martin.