What could be the issue with this code? How come the MsgBox is still being displayed regardless of whether the user clicks the checkbox or not?

Even without selecting the checkbox, a MsgBox still pops up...

In my code below, regardless of whether the user checks the checkbox or not, it will always redirect to Google: If the user selects the checkbox, then it redirects to www.google.com. However, if the user forgets to check the checkbox, a message box with an OK button appears. After clicking OK, it should redirect to www.google.com.

What I need is:

If a user forgets to select any checkboxes, display a MsgBox with an OK button and keep them on the same page. Otherwise, if the user does select any checkboxes, then redirect them to www.google.com.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <title>Untitled Page</title>
</head>

<body>
    <form id="form1" runat="server">
        <div>
            <asp:CheckBox ID="CheckBox1" runat="server" />
            <asp:CheckBox ID="CheckBox2" runat="server" />
        </div;

        <asp:Button ID="Button1" runat="server" OnClientClick ="return ConfirmSelection(this.form);" Text="Button" />

    </form>
    <script type="text/javascript">
        function ConfirmSelection(frm)
        {
            for (i=0; i<=1; i++) {
                //chkSubjectOfInterest is the id of your checkbox control

                if (frm.elements[i].name.indexOf('chkSubjectOfInterest') != -1)
                {
                    if (frm.elements[i].checked)
                    {
                        return true
                    }
                }
            }
            alert('You haven\'t selected an item yet!')
            return false;
        }
    </script>
</body;>
</html;>

Answer №1

Is this snippet correct?

 for (i=0; i   {

The corrected version should look like this:

for (i=0; i <= loopCount; i++)
{

}

Answer №2

if (i=0; i > {

Is this code missing something?


for (i=0; i<anotherthing.length;i++)   { 

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

Activate jqGrid's navigation bar save icon when the ondblClickRow event is triggered

After setting the jqGrid row edit on the ondblClickRow event, how can I enable the save icon on the navigation bar when a row is double clicked? ondblClickRow: function (rowid) { jQuery(this).jqGrid('editRow', rowid, true, null, null); ...

Is there an easy way to determine if an element inside a Vue component is overflowing?

I created a unique component called ResultPill which includes a tooltip feature (implemented using vuikit). The text displayed in the tooltip is determined by a getter function called tooltip, utilizing vue-property-decorator. Here are the relevant parts o ...

Struggling to efficiently handle imported JSON data using VUE.JS JavaScript?

Struggling to extract specific information from JSON data that I need to import. Here is the sample data I'm working with: I am trying to extract details like the name, description, and professor for each entry. This is how I'm importing the d ...

Display the outcomes of two MongoDB queries simultaneously on a single page

As I dive into the world of MongoDB and Node.js/Express, I find myself struggling to fully grasp some of the concepts. Forgive my inexperience, but I haven't been able to locate a clear answer for what I'm trying to achieve. My goal is straight ...

Acquire JSON information from PHP utilizing JavaScript

I am a beginner with JSON and I'm retrieving data from PHP code in JSON format. [ { "Title": "New Event", "TYPE": "info", "StartsAt": "16 November 201512:00", "EndsAt": "25 November 201512:00" }, { ...

Updating multiple subdocuments with Mongoose

My goal is to update a specific subdocument called addresses (which is working fine) and then update all other subdocuments except the one that was just changed. Whenever an address is changed to have is_preferred set to true, I need to update the previous ...

What are the advantages of passing state from child components up in React?

I have been attempting to update the state within the App component from a child component, but I am concerned that this approach may cause issues later in my application. I've experimented with passing down the setFunction to the child components an ...

Can the performance of ASP.Net be enhanced by declaring variables within an If statement?

I created two functions as examples. I'm seeking your advice on which one is considered better practice. Is Test2 more efficient in terms of performance because it declares fewer variables and may use less memory on the system? Function Test1() ...

Creating an HTML string and then displaying its outer HTML in IE10 can be easily achieved. Just write the

My task is to write an HTML string to an element and then retrieve the resulting outer HTML from that element. This needs to be operational in IE10, latest versions of FF, Chrome, Safari, Android, iOS Safari but does not have to support any older browsers. ...

Troubleshooting: Why Laravel 5 VueJS Integration is Failing

I have recently set up a Laravel project and am attempting to integrate Vue.js into it. After running the following commands in my terminal: npm install npm run dev The commands executed without any errors. However, when I tried to import the default Vue ...

How can I change the behavior of the Enter key in text fields to automatically submit the form, rather than requiring the user to

Utilizing material UI for my component library, I have a compact dialog with a "recover password" button placed within the form. However, upon adding this button, I noticed that pressing the "enter" key in the text fields triggers the onClick event of the ...

Conceal a div until reaching the end of the webpage by scrolling

Currently, I am working on a web page inspired by music release pages (check out an example here). My goal is to have certain hidden divs at the bottom of the page only reveal themselves once the user has scrolled all the way down, with a delay of a few se ...

What could be the reason behind the failure of my JSON post method on the local web server for my JSON file?

Recently, I decided to dive into learning Javascript with the goal of creating a website that utilizes JSON files for storage. So far, I have managed to get the GET method to work: $.ajax({ type: 'GET', url: 'Projects/Sample/data.json&a ...

Ways to toggle the visibility of a div with a click event?

I am working on a project where I have a list view of items. I want to implement a feature where when a user clicks on an item, a hidden div below it will appear with options like price, quantity, and other details. I am looking for guidance on how to achi ...

Express.Js having identical parameter names that are not being passed

I'm currently experiencing an issue with Express.Js. When I visit /article/14, the parameters returned are: { artId: '14' } { artId: 'img' } I'm puzzled about the presence of the img part and why the value is repeated. Strang ...

What steps can be taken to effectively build a test suite architecture using Jest?

After exploring all the available resources on the Jest documentation website, including various guides and examples, I have yet to find a solution to my specific question. I am in search of a methodology that would enable me to individually run test case ...

Error: The filter argument must be in object form

Currently I am in the process of developing a REST API with an endpoint for posting movies. The request body is expected to contain only the movie title, which needs to be validated for presence. Upon receiving the title, I need to fetch other movie detail ...

In the realm of React Native, an error arises when attempting to access 'this._nativeModule.isBluetoothEnabled', as the reference to null prevents it from

Recently, I delved into working with react native and attempted to incorporate react-native-bluetooth-classic into my project. The URL for the API overview can be found here. However, I encountered an issue that has me stuck: "TypeError: null is not ...

Alternative method for handling web requests in case JavaScript is not enabled

Issue: i) I am developing a JSF2 application and need to implement a tab control on a page. When a user clicks on a tab, the content for the panel below should be loaded from an xhtml file on the server using an ajax call. ii) I want this functionality ...

Strengthening the vulnerability of open redirects in JavaScript

let input=document.getElementById("example").value; let newUrl= "http://localhost/app/default.aspx?example="+input; Window.showModalDialog(newUrl); I've noticed that the showModalDialog method may result in a potential open redirect vulnerability. Is ...