javascript thread: error checking? better/different way.........
A string is an array so you can do
For(int I = 0; I < Len(Str); +i)
{
var ThisChar = Str[i];
if (ThisChar == "1")
...
}
or something like that
Iain
-----Original Message-----
From: Sukhi Samra [mailto:sukhdeepsamra@h...]
Sent: 24 October 2001 19:35
To: javascript
Subject: [javascript] RE: error checking? better/different way.........
Currently in my javascript strValue stores the values of all the titles
such
as "12356"
strValue = strValue +
document.frmMemberDetails.cboTitle.options[i].value;
is there a way to do somthing like this....
---------->
string= "12345"
read string one by one
if string has "1" then
check if string has "2" or "3" or "4" or "5" or "6" or "7" or
"8" or "9"
alert "can have only one thing"
<-----------
how can i read a string one by one...any way to do that??
Thanks Iain for your help..although it's bit hard to do taht way..do you
have any suggestions for the above..?
>From: "Iain Downs" <idowns@d...>
>Reply-To: "javascript" <javascript@p...>
>To: "javascript" <javascript@p...>
>Subject: [javascript] RE: error checking? better/different way.........
>Date: Wed, 24 Oct 2001 18:59:25 +0100
>
>The easiest way to do this sort of thing is to set up the
>relationships/rules in an array.
>
>It's more complex to program but your rules are then driven by data
>which makes it much easier.
>
>
>So your array may look like
>
>{"Director", -1, 1},
>{"Boss", 0, -1},
>{"Worker", 1, 0}
>
>the ide here being that the second element is the index of an
>'equivalent' (Boss is equivalent to a director). The third entry says
>the max number you can have .
>
>So you could run through your results and increment each element OR
it's
>equivalent and see if you have > the rul.
>
>This is probably not what you want - it's simply a pointer to goive you
>ideas.
>
>Iain
>
>
>-----Original Message-----
>From: Sukhi Samra [mailto:sukhdeepsamra@h...]
>Sent: 24 October 2001 18:06
>To: javascript
>Subject: [javascript] error checking? better/different way.........
>
>I have 10 different titles stored in one table:
>
>Title_code|Title_description
>1 Project Manager
>2 Senior Manager
>3 Director
>4 Assistant
>5 CFN
>6 CFN Designate
>7 FTN
>8 Analyst
>9 acting Director
>
>I have a combo box on title.asp page which shows all these titles from
>tbltitle.
>
>user can multiselect these titles. But i have business rules for
titles,
>
>which are
>
>1)Senior manager can be acting Director
>2)Director can be CFN Designate
>3)all other can have only one title assigned to them
>
>if person has selected 1 and 2 or vice versa. I want to display error
>saying this is not allowed..To do that i have follwoing javascript:
>
> function validateThis()
> {
>
> // THIS RETURNS VALUES OF LIST THAT ARE SELECTED
> strValue = "";
> for(var i = 0 ;i< document.frmMemberDetails.cboTitle.length;i++)
> {
>
> if (document.frmMemberDetails.cboTitle.options[i].selected)
> {
> // alert(document.frmMemberDetails.cboTitle.options[i].value)
>
> strValue = strValue + document.frmMemberDetails.cboTitle.options
>[i].value;
>
> }
>
> }
>
> //RULES
> if (strValue == "12")
> {
> alert("Please select only one Title");
> }
>
>
> }
> </script>
>
>************My question is, to make sure that User just select Project
>Manager, but none of any other ...means i have to write all teh
possible
>
>combinations...such as 12, 13, 14, 15, 16, etc etc..(and i have to do
>these checking for all other Titles too...).adn i think they are more
>than
>40-50..is there a DIFFERENT/BETTER way to write this?? or am i just
>stuck
>with this one??????????********)
>
>Pleaseeeeeeeeee let me know.........Thanksss you so much in advance..
>
>Sukhi