JavaScript requires a function to be passed as an argument

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.

Answer №1

The issue lies in the following line:

var selection = document.getElementById("<%: preferedlist.ClientID%>");

You have assigned the variable name 'selection' to the container of the checkboxlist. It is clear that using 'confirm' as a variable name will conflict with the original JavaScript confirm box function :). Please choose a different variable name to avoid confusion.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve all elements from an array that has been imported through the fs module

To extract the values from the array jsonParsed.students[actStudent].evnetsPartaken, which may look like [1,2,0] (note: check attachments for full data), I need a way to reference each value in correlation to the event number in the configEvents JSON array ...

How can you conceal an HTML element when the user is using an iOS device?

I need the code to determine if a user is using an iOS device and, if not, hide the HTML input type "Play" button. So, I'm uncertain whether my iOS detection is correct, the hiding of the "Play" button in the code, or both: <!DOCTYPE html> < ...

Tips for using ng-repeat in AngularJs to filter (key, value) pairs

I am trying to achieve the following: <div ng-controller="TestCtrl"> <div ng-repeat="(k,v) in items | filter:hasSecurityId"> {{k}} {{v.pos}} </div> </div> Code snippet for AngularJs: function TestCtrl($scope) { ...

Having trouble executing the typescript build task: Command 'C:Program' is not valid as an internal or external command

I'm currently working on converting typescript code to JavaScript and have been following the steps outlined in the documentation. To automate the compilation of .ts files, I set up a watch task triggered by pressing Ctrl+Shift+B. However, upon runni ...

Are you looking for outcomes related to Bootstrap typeahead feature?

I am facing an issue with returning results for the bootstrap typeahead after making an ajax request. Strangely, it works fine without initiating the ajax request. The code that doesn't work: $(".typeahead").typeahead({ source: function(query, pr ...

Why is only the peak of the wave visible? I am eager to showcase the full extent of its beauty

Having an issue with the appearance of a superposed wave using threejs. When displayed, the wave made from plane material only shows the upper half, but when turned upside down using mouse dragging, it appears correctly. // Turn the wave plane upside down ...

Break up the JavaScript code into modules to avoid duplicating blocks of code detected by

There is a block of code that SONAR has identified as duplicate. I am looking for guidance on how to address this issue. import fields from '../../utils/utils'; dispatch( fields.change([ { id: 'userData', value: ...

Utilizing the JQuery .not() method to fade out all div elements except for the one that is selected and its corresponding children

I have a grid consisting of images, each with a hover function that changes the opacity of a div. The image is set as a background image, while the information is placed within a div in each grid-item. <div class="grid"> <div class="grid-it ...

Could there be a more efficient method to enable support for all video formats?

I have a case statement in my video validation function that checks for specific file extensions of video formats. However, I am wondering if there is a shorter way to write the code in order to allow all video formats instead of creating a long list of al ...

Go to a different page section using MUI 5

I am currently working on a React application and I want to implement a functionality where pressing a button on my Nav Bar will navigate to a specific section on the first page. To achieve this, I have created an onClick function for my button: const onNa ...

Attempting to establish a cookie from the server end, however, it is not being successfully set on my client

Attempting to set a cookie on the client browser from the server side using Node.js and Express. When signing up, the cookie is properly sent in the response object but not being set on the client browser. Additionally, when trying to access a protected AP ...

Combine NPM dependencies into a single JavaScript file

Attempting to integrate Swig, a template language, into Parse Cloud Code with Express can be quite challenging. Parse Cloud Code is a Node/Express host that has restrictions on using NPM, which can be frustrating. However, there may still be a way to load ...

The latest version of fork-ts-checker-webpack-plugin, version 5, cannot be reached from @vue/cli-plugin-types

Currently, I am updating the build container in my project from node:10-alpine to node:14-alpine. However, when I run npm ci (after rebuilding package-lock.json), I encounter the following error: npm ERR! fork-ts-checker-webpack-plugin-v5 not accessible fr ...

Undesirable flickering animation on button

Is there a way to display a dynamic button that follows the mouse cursor when hovering over an image? If you want to see the code in action, check out this codepen link. const box = document.getElementById("box"); function movebox(e) { box.style.lef ...

Is there a way to access the userID in the React.js front-end?

As I work on completing my Full Stack Web app with JWT token authentication based on roles, I find myself facing challenges with the front-end development. Specifically, I am unsure of the best practice for retrieving the UserID in the front-end to facil ...

Transferring information through AJAX and fetching through PHP

Below is my current AJAX code setup: optionScope.data().stage = 'b'; $.ajax({ url: "functions/contact.php", type: "post", data: {'stage': optionScope.data().stage}, success: function(data, status) { ...

Utilizing Javascript for logging into Facebook

Feeling frustrated! I've been struggling to implement the Facebook Login pop-up on my website using the Facebook JavaScript API. Despite following tutorials, I can't seem to make the login pop-up appear. Instead, when I go through the login pro ...

The scaling of the slick carousel image is not working as expected

Having an issue with the Slick carousel where images are not resizing based on browser size (original size is 300x228px). Just to clarify: When I shrink the browser window, the number of slides decreases but the images remain the same size. I've bee ...

Discovering the exact distance between a 'li' and a 'div' element

Currently, I am in the process of converting HTML to JSON. Here is an example of the HTML I am working with: <div class="treeprofit" id="divTreeViewIncomeDetails" style="height: auto;"> <li><span class="fa fa-folder-open highlight" ...

Tips for sending data from an HTML page to an Angular custom element

I have successfully created an angular custom element from an angular component that I would like to call from a standard HTML page. The custom element requires a parameter, which functions properly when called as a component within an angular project. Ho ...