473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Validator code problem.

Hi,

I have a code that returns invalid if a dropdownlist is at index 0.

function clientValidateCboBx(source, args)
{
var dropdown = document.getElementById(source.controltovalidate);
if(dropdown.selectedIndex == 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

As above it works fine, but I want it to only return invalid if the
control it's validating is enabled, if it's disabled it should always
be valid. I tried adding && dropdownlist.enabled == true to the if
statement, but then the validator always returns true even when the
selectedIndex == 0.

Any ideas on a solution?

Thanks

Oct 13 '05 #1
5 1946

Assimalyst wrote:
Hi,

I have a code that returns invalid if a dropdownlist is at index 0.

function clientValidateCboBx(source, args)
{
var dropdown = document.getElementById(source.controltovalidate);
I don't see enough of your script to see what it is that you're passing
as a "source" argument. However, getElementById() method expects a
string argument, and like the name says an id.

For example:

<div id = "myId">...</div>

Then in your script:

var myDiv = document.getElementById("myId");
if(dropdown.selectedIndex == 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

As above it works fine, but I want it to only return invalid if the
control it's validating is enabled, if it's disabled it should always
be valid. I tried adding && dropdownlist.enabled == true to the if
statement, but then the validator always returns true even when the
selectedIndex == 0.

Any ideas on a solution?

Thanks


Oct 13 '05 #2
Assimalyst wrote:
Hi,

I have a code that returns invalid if a dropdownlist is at index 0.

function clientValidateCboBx(source, args)
{
var dropdown = document.getElementById(source.controltovalidate);
if(dropdown.selectedIndex == 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

As above it works fine, but I want it to only return invalid if the
control it's validating is enabled, if it's disabled it should always
be valid. I tried adding && dropdownlist.enabled == true to the if
statement, but then the validator always returns true even when the
selectedIndex == 0.

Any ideas on a solution?


args.IsValid = !dropdown.enabled && dropdown.selectedIndex;
Mick
Oct 13 '05 #3
Mick White wrote:
Assimalyst wrote:

<snip>
... . I tried adding && dropdownlist.enabled == true ... <snip> Any ideas on a solution?


args.IsValid = !dropdown.enabled && dropdown.selectedIndex;


Typo? You know the pertinent property is called - disabled - and is true
when the control is disabled and false otherwise?

Richard.
Oct 13 '05 #4
Richard Cornford wrote:
Mick White wrote:

args.IsValid = !dropdown.enabled && dropdown.selectedIndex;

Typo? You know the pertinent property is called - disabled - and is true
when the control is disabled and false otherwise?

Yes, I invented the property "enabled", but the logic is sound:
args.IsValid = dropdown.disabled && dropdown.selectedIndex;

Mick
Oct 13 '05 #5
Lee
Mick White said:

Richard Cornford wrote:
Mick White wrote:

args.IsValid = !dropdown.enabled && dropdown.selectedIndex;

Typo? You know the pertinent property is called - disabled - and is true
when the control is disabled and false otherwise?

Yes, I invented the property "enabled", but the logic is sound:
args.IsValid = dropdown.disabled && dropdown.selectedIndex;


Almost:

args.IsValid = dropdown.disabled || dropdown.selectedIndex;

Oct 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Antho | last post by:
Firstly, thank you to everyone that replied to my OP. I am new to the PHP world and so its great that there are people out there who are prepared to share their knowledge. Anyway, I am...
5
by: johnleemk | last post by:
I download the source for W3C's validator from http://validator.w3.org/source/ to validate pages on my own server. I commented a block of code that checks for non-public hosts so the validator...
0
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These...
2
by: VSK | last post by:
Hi all, I have a .ascx file with dropdownbox (SSN, EmpName) textbox submit button regular expression validator( controltovalidate is the above textbox) Now i want to change the Regular...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
1
by: bennett | last post by:
At http://www.brainjammer.com/testing/validator_test.aspx I have a text field where you can enter text, and a button where if you click the button, it sets the value of a label below it, to...
4
by: Alan Silver | last post by:
Hello, I have a site that produces 100% valid XHTML 1.0 Strict when viewed in a browser (IE, Firefox, etc). I just tried validating the site with an on-line validator, and got several errors. ...
0
by: Gonza | last post by:
Hi group, i'm trying to add a customvalidator control to a custom web control. The problem is i'm getting a "Unable to find control id..." exception. Here is the code: public class CuitTextBox :...
1
by: Gonza | last post by:
Hi group, i'm trying to add a customvalidator control to a custom web control. The problem is i'm getting a "Unable to find control id..." exception. Here is the code: public class CuitTextBox :...
37
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.