Solved

Javascript adn required field validation asp.net

Posted on 2010-11-09
3
437 Views
Last Modified: 2012-06-21
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
Comment
Question by:JMRFan4Life
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 200 total points
ID: 34094584
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
 
LVL 13

Accepted Solution

by:
devlab2012 earned 300 total points
ID: 34094843
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
 

Author Closing Comment

by:JMRFan4Life
ID: 34094966
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question