470,618 Members | 1,750 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,618 developers. It's quick & easy.

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 1896

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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tom Pearson | last post: by
reply views Thread by Gonza | last post: by
1 post views Thread by Gonza | last post: by
37 posts views Thread by Prisoner at War | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.