Issue with disabling the submit button when two textboxes are empty is not functioning as expected

My goal is to have two text-boxes and one button on my web page. The button should be disabled if either of the textboxes is empty. However, with the current code, the button remains enabled as long as at least one of the textboxes has a value.

HTML

<asp:TextBox ID="TextBox2" runat="server" onblur = "Toggle()"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server" onblur = "Toggle()"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" Enabled = "false" />

JavaScript

 function Toggle() {
        var txt1 = document.getElementById("<%=TextBox1.ClientID %>");
        var txt2 = document.getElementById("<%=TextBox2.ClientID %>");
        var btn = document.getElementById("<%=Button1.ClientID %>");
        if (txt1.value == "" && txt2.value == "") {
            btn.disabled = true;
        } else {
            btn.disabled = false;
        }
    }

Answer №1

Attempt

if (input1.value && input2.value) button.disabled = false;
else button.disabled = true;

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

Can you explain the mechanics behind the animation of the upvote button on steemit.com?

Behold the upvote button of steemit.com: <span class="Icon chevron-up-circle" style="display: inline-block; width: 1.12rem; height: 1.12rem;"> <svg enable-background="new 0 0 33 33" version="1.1" viewBox="0 0 33 33" xml:space="preserve" xmlns=" ...

What is the best way to create an asp.net menu that spans the full width of the page

Currently, I am in the process of developing an asp.net website and encountered an issue with creating a horizontal asp menu that spans the full width of the screen. Each menu item should ideally be 10% of the total width. I have tried setting the menu wi ...

Troubleshooting Problems with Ajax Servlets

When I perform a search, the results are returned and shortly after, the page redirects to a servlet displaying raw JSON data. It's a bit confusing for me. This JSP form submission: <form class="col-lg-12" action="./urllinks" method="GET" id="sea ...

Learn to save Canvas graphics as an image file with the powerful combination of fabric.js and React

I am currently utilizing fabric.js in a React application. I encountered an issue while attempting to export the entire canvas as an image, outlined below: The canvas resets after clicking the export button. When zoomed or panned, I am unable to export co ...

Requesting data asynchronously using AJAX and displaying the filtered results on a webpage using JSON

When I send a request to my node.js server for a .json file containing person information (first name, last name), I want the data to be filtered based on user input. For example: When I request the .json file from the server, it gives me a list of people ...

Issue encountered when utilizing FontAwesome in xhtml file in jdeveloper

Attempting to integrate font-awesome into my .xhtml page is proving to be a challenge, resulting in errors as shown in the image below. My development environment is Jdeveloper 12.2.1. Despite researching various topics, I have yet to find a solution. An ...

What is the best way to calculate the total number of results using ajax?

Encountering an issue with the total count of ajax search results. Getting an error message "Method Illuminate\Database\Eloquent\Collection::total does not exist." when using directives, for example: <div class="searched-item"&g ...

AJAX enhancing the functionality of the webgrid with dynamic filtering

I'm encountering a problem with implementing JS on my webgrid for sorting purposes. The scenario is that a user enters a string into a textbox and the webgrid below is refreshed (filtered based on matching results) without the entire page being refres ...

In the absence of an Avatar, verify the gender from the JSON data and insert it into the image

I have created my very first app where users can upload their avatars and set their gender. If a user (in this case, a girl) does not upload an avatar, I want to check the JSON data for their gender information. Based on this gender information, I want to ...

An effective way to mimic an un-exported (private) function within a user module using Jest

In my code, I have a function that handles API requests called "private" and several other functions that initiate specific requests with configuration objects. For example, in the requestUploadStatementFile file. I want to test these public functions, bu ...

What is the best way to generate a div with a dynamically changing variable as its ID?

Creating a quiz where the user can choose how many questions to answer. A function is used to generate individual question divs based on the user's input. Each question displays a Chinese character, and the user must select the correct translation. ...

What can I do to ensure that the values of a vector in an array remain constant?

Is there a way to store vector data in an array without it being affected when the original vector values are changed? I inserted a vector into an array and when I modified its values, the corresponding values in the array also changed. const array10 = []; ...

Encountering a problem in React when trying to install a color detection library

Hey there, I'm working on a Spotify-clone project where I want to detect the dominant color of an image and use it as the background color. Unfortunately, I've run into some errors while trying to integrate libraries like color-theif, node-vibran ...

When a URL is entered, information is not retrieved from the database

I have a simple app setup where the data (iPhones from the database) is fetched in the AppComponent itself. ngOnInit(): void { this.iphoneservice.fetchIphones(); } The fetchIphones method is located in my iPhoneService file and consists of 3 functio ...

eliminate the offspring of a component (chessboard)

Hey there! I'm currently working on developing a chess game and I could really use your expertise to help me solve an issue. In my code, when I try to move a piece in the game, this is what happens: 1. First, I remove the existing piece from its cu ...

The specified subpath './lib/tokenize' does not match any defined "exports"

As a newcomer to React, I've been facing some challenges while trying to get started. Despite searching on Google and other platforms, I couldn't find a solution to my problem. I was attempting to run code from a YouTube channel called Lama Dev b ...

Using JavaScript in Internet Explorer 11, you can open multiple tabs without the UrlReferrer being null

I have tried numerous solutions to open multiple tabs in IE 11, but none of them seem to work for me. In Chrome, everything works smoothly with a simple window.open(url) command. When I try to open tabs using an iterative JavaScript code snippet, only one ...

The slicing of jQuery parent elements

Hey there! I recently created a simulated "Load More" feature for certain elements within divs. However, I've encountered an issue where clicking on the Load More button causes all elements in both my first and second containers to load simultaneously ...

Discovering the actual file path of an uploaded document in Asp.Net Mvc

When trying to use an HTML input file to select a file, I encountered an issue where JQUERY would return a fake path instead of the actual one. $("#inputfile").val() I am looking to obtain the selected file's actual path, such as: D:\Documen ...

What is the best way to store JSON data in a MySQL database?

I am facing a challenge with a JavaScript rich page that is sending a large JSON formatted data to PHP for insertion into a MySQL database. The JSON contains user input strings, some of which may include basic HTML tags like <a> and <strong>. ...