[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

Javascript adn required field validation asp.net

hi,

i am using a required field validation on my dropdownlist. i have two drop downs and would like to hide one of the validators if both items have not been filled out. There should be a way to do this with javascript or JQuery. not sure how to do the test.

Thanks
0
JMRFan4Life
Asked:
JMRFan4Life
2 Solutions
 
guru_samiCommented:
Can you give exact scenario when you want to disable.
The idea is you get the two dropdown list by IDs in javascript and then see if the value for them is nothing or some pre-assigned, if so call ValidatorEnable method and disable the validator you want to.

Something like here: http://weblogs.asp.net/gurusarkar/archive/2010/07/26/enable-disable-validator-controls-from-javascript.aspx

If you can provide some of your code, we can get better idea.
0
 
devlab2012Commented:
I assume that you have two validators val1 and val2. And a button to submit the form. Try the following implementation:

1. Add onclientclick="custValidate()" for the button.

3. The code for custValidate() function will be:

function custValidate()
{
//enable both validators
ValidatorEnable(val1, true);
ValidatorEnable(val2, true);

//run the validation
ValidatorValidate(val1);
ValidatorValidate(val2);

//check if both the validations fail, disable any one of these
if (val1.isvalid == false && val2.isvalid == false)
{
ValidatorEnable(val2, false);
ValidatorValidate(val2);
}

}
0
 
JMRFan4LifeAuthor Commented:
I actually used some javascript to get this done. below is my code actually used, but the examples above work jsut as well.

            if (ddlFPGenderChild1.selectedIndex == 0 && ddlFPRelationChild1.selectedIndex == 0) {
              $(rfvrel1valid).css({ "visibility": "visible", "display": "none" });
            };

i use selectedIndex to determine if the dropdowns have been selected or not. This case if first position is shown for both drop downs then hide one.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now