Validating 2 textbox controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Im trying to do a function to validation two textbox controls. I want the
user to enter in text to either txtSurname or txtCompanyName but not both. Is
my logic wrong and if so can someone help me change this to achieve my goal.
Im really terrible at this and am under pressure to get it done so any help
at all would be appreciated.

function ValidateSurnameCompanyEntered(sender, args)
{
var txtSName = document.WebForm2.txtSurname;
var txtCompName = document.WebForm2.txtCompanyName;
args.IsValid = ((txtSName.text.length>0 && !(txtCompName.text.length < 0))
|| txtSName.text.length> 0 && (txtCompName.text.length < 0));
}
 
I'd suggest reading up on programming logic...

From what I've seen, you've got the javascript idea from me, and populating
the IsValid from somewhere else... The IsValid bit is not readible, even
though it makes the function shorter...

Personally I'd do this.

function ValidateSurnameCompanyEntered(sender, args)
{
var SurnameLength = document.WebForm2.txtSurname.text.length;
var CompanyLength = document.WebForm2.txtCompanyName.text.length;

if ( SurnameLength > 0 && CompanyLength == 0 )
{
args.IsValid = true;
}

if ( SurnameLength == 0 && CompanyLength > 0 )
{
args.IsValid = true;
}

// if both or neither then we get here...
args.IsValid = false;
}
 
Would you not use the TextChanged event from each textbox to enable/disable
the other so that there can never be text in both boxes in the first place?

--Liam.
 
This would require a post back.... Over a slow internet connection, this can
be annoying when validating data.

I've been using some internet sites late that are running asp.net, and they
postback for everything, and even though I'm on a broadband connection (be
it 512kb) i find it really annoying.
 
Back
Top