By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Validator code problem.

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.