Toggle the ASP validation control using JavaScript

I am looking to control the validation of my form using JavaScript. When a user clicks on a radio button in a list (yes or no), 2-3 rows are displayed. If the user selects "Yes," they must enter input into a textbox in one of those rows. To enforce this, I have set up required field validators. On page load, all validators are disabled and are enabled via JavaScript with ValidatorEnable(control, enable) when needed. However, when a radio button is clicked, the rows become visible and an error message from the validation control appears simultaneously. I want the error message to only show when the submit button is clicked. How can I achieve this?

Answer №1

Insert the following code immediately after calling the ValidatorEnable(control, enable) method:

if (control.style.visibility == "visible") {
     control.style.visibility = "hidden";
} else {
     control.style.display = "none";
}

Answer №2

function CheckValidatorsOnPage() {
    var hasValidators = false;

    try {
        if (Page_Validators.length > 0) {
            hasValidators = true;
        }
    }
    catch (error) {
    }

    return hasValidators;
}

function ToggleValidationGroup(validationGroupName, isEnabled) {
    if (CheckValidatorsOnPage()) {
        for (i = 0; i < Page_Validators.length; i++) {
            if (Page_Validators[i].validationGroup == validationGroupName) {
                ValidatorEnable(Page_Validators[i], isEnabled);
            }
        }
    }
}

Then make the following call:

ToggleValidationGroup('validationgroup', false);

I believe this function will assist you...

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

What is the reason that PHP has the ability to set Cookies but Local Storage does not?

Let's take a step back to the era of cookies, not too far back since they are considered old but still quite relevant. PHP allows you to set and read them even though they are a client-side technology; however, JavaScript can also be used completely o ...

Unable to access image from JSON within Mobile Angular Ui utilizing Angular Js

Currently, I am able to retrieve various data from JSON such as Price and Display Order, but I am facing difficulty in fetching the image. HTML: <div ng-controller="chooseProductDescription"> <div ng-repeat="cat in productDescrip ...

How do you go about installing the most recent version of a module through Private NPM?

When using a private npm registry, I have noticed that some common commands do not seem to be functioning properly: npm install without specifying a specific @version :: issue npm outdated :: issue npm update :: issue npm view <private-packag ...

``Can you share your insights on transferring data from one controller to a service, and then accessing that data on another controller during the same

I'm encountering an issue with passing data from one controller to another using a service. To achieve this, I have implemented prototype inheritance using the $rootScope in my controller and broadcasting the object so that other controllers can acce ...

Issue with ExpressJS Twig module: inability to execute async functions even after adjusting settings as needed

Currently, I am facing an issue while trying to load an array from mongoose into a twig rendered list. An error message keeps popping up: TwigException: You are using Twig.js in sync mode in combination with async extensions. I have made sure to care ...

The ajax keypress event is malfunctioning and the ActionResult parameter is failing to capture any data

I am facing an issue where I want to update the value of a textbox using AJAX on keypress event, but the controller is not receiving any value to perform the calculation (it's receiving null). <script> $('#TotDiscnt').keypress(fu ...

What potential problem is arising from Jest's use of "transformIgnorePatterns" and how does it impact importing scoped CSS in a React application?

Currently facing a challenge with Jest testing in my React application following the addition of transformIgnorePatterns to the Jest settings. The default settings I included in the "jest" section of the root package.json file are as follows: "transfo ...

Guide for displaying and hiding an image using a button or link in Next.js

I'm a beginner with React and Next.js, and I have the following code snippet: import Link from 'next/link'; import Image from 'next/image'; async function getPokedex() { const response = await fetch(`http://localhost:3000/api/p ...

The Angular Syncfusion schedule is unable to call upon an object that may potentially be 'undefined'

Currently, I am developing an application using Angular Syncfusion to allow users to view and book appointments. I found a helpful resource at the following link: Below you can find the code snippet I have been working on: <ejs-schedule #scheduleObj ...

The Vue.js scripts and styles declared in the index.html file seem to be malfunctioning

I acquired a theme that includes html, css3, and js files, and I included the file path as shown below: <!-- Basic --> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Porto - Responsive HTML5 Te ...

How can we verify the validity of URLs based on their length, presence of capital letters, and specific whole words?

I'm currently working on a piece of code that verifies the URL provided by users during sign-up for my application. I want to implement the following restrictions: URL must be at least 3 characters long No capital letters allowed Avoid certain words ...

ajax request encountered access denial when attempting to call wcf service

I have set up an Amazon EC2 instance and deployed my .NET web application on port 80, with the WCF service running on port 1212. While I can access both the application and service locally on the remote session, attempting to make Ajax requests over the i ...

Similar to `util.inspect` in Node.js, Deno also has a function

Is there a utility function in Deno that can stringify an Object or primitive similar to Node.js util.inspect? For instance, if I have a JSON object in Node.js and want to display its contents: > m = {k1:'v1', k2:'v2'} { k1: ' ...

Arrange a div close to another div with the help of absolute positioning

My goal is to create a tooltip-like positioning for an element within the same container as another element. When clicked, this particular element will display a div containing a table. You can find the complete code here: http://jsbin.com/xihebol When s ...

Problem with Ajax functionality on Jquery Dialog

I have implemented a Jquery.dialog feature in my application for sending messages. When the user clicks on "new", the dialog box appears, allowing them to select the recipient (currently working with IDs instead of usernames). On the first opening of the ...

What is the best way to transform the pages extracted through the Notion API into slugs?

I'm new to Next.js and Notion API, and I want to create a blog site on my personal website using the Notion API. While I can easily pull the posts, I am facing a challenge in slugifying the endpoint IDs with post titles. When attempting this based on ...

Is it really necessary to still think poorly of JavaScript in 2011?

Here's an intriguing question for you. I've tested out a variety of popular websites, including Facebook, and I've noticed that many features still work perfectly fine even when JavaScript is disabled. People always used to say that JavaScr ...

Integrating Express into a React Webpack project

I am currently in the process of integrating express into my React project to establish connections with databases for storing form data. As of now, I am using webpack to create a dev server that displays my React view. My technology stack includes... Web ...

Learn how to incorporate a click event with the <nuxt-img> component in Vue

I am encountering an issue in my vue-app where I need to make a <nuxt-img /> clickable. I attempted to achieve this by using the following code: <nuxt-img :src="image.src" @click="isClickable ? doSomeStuff : null" /> Howeve ...

Creating a unique WooCommerce product category dropdown shortcode for your website

I am having trouble implementing a WooCommerce categories dropdown shortcode. Although I can see the drop-down menu, selecting a category does not seem to trigger any action. Shortcode: [product_categories_dropdown orderby="title" count="0" hierarchical=" ...