Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript: String compare without case sentative

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
how do you compare two strings with javascript, without having the problem of it being case sentative, it things

&quot;cost&quot; == &quot;Cost&quot; is false. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
var str1 = document.all(tree[j][2],i).value;
var str2 = tree[j][5];
alert(&quot;Compare : &quot; + str1.toLowerCase()+ &quot; == &quot; + str2.toLowerCase());
if (str1.toLowerCase() == str2.toLowerCase())

that works for words that dont have spaces in them, but when I Try to compare two strings, the first one(Above) is cut off at the space, and you only see the remaining string. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
I use this for IE

var str1 = document.all(tree[j][2],i).label;
var str2 = tree[j][5];
if (str1.toLowerCase() == str2.toLowerCase())
{ //if current control matches the label for the &quot;True&quot; parent
document.all(tree[j][2],i).checked = true;


but in NS , it says Str1 has no properties, it's also messing up which Checkbox I Get ahold of, ARG! [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Netscape doesn't have 'document.all'; you can try

document(tree[j][2],i).value

...but I can't see enough of your code to know if it will work. [sig][/sig]
 
I realize that, but yer not listening, I am telling you what I used for IE, the IE and NS code should be the same, just the difference on how you access the document content, in this case netscape uses document.forms[0][myindexforitem].properties. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
>>but in NS , it says Str1 has no properties, it's also messing up which Checkbox I Get ahold of, ARG!

How can I help with your Netscape code, unless you show me some? Yer not saying enough. For example, you reference the '.label' property, but Netscape has no support for the '.label' property of a form element. I have nothing to go on until I see the complete function.

To say the IE and Netscape code should be the same is like saying &quot;the candidates should stick to the issues&quot; ;-). They have such different Document Object models that it's quite often just plain impossible to use the same wrapper code, unless you abstract it all and create a custom object. [sig][/sig]
 
Showchild and ShowParent function, for the javascript that checks boxes of child boxes, and parent boxes, the parent function has bene disabled for netscape since netscape cant reference object correctly, and cannot distinguish difference between a string and an index location.

[tt]
function ShowChild(HID, LID, status) //HID/LID of current, and status
{
for(var j=0; j<=max; j++) //Loop through array rows
{
if ((tree[j][3] == HID) && (tree[j][4] == LID)) //if current has H/L as their parent
{
<% if instr(ucase(Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;)), &quot;MSIE&quot;) <> 0 then %>
if (document.all(tree[j][2]).length > 1) //if multiple with same name
{
for (i=0; i<document.all(tree[j][2]).length; i++) //go through each
document.all(tree[j][2],i).checked = status; //change each
}
else
{
document.all(tree[j][2]).checked = status; //if single change.
}
<% else %>
if (document.forms[0][tree[j][2]].length > 1) //if multiple with same name
{
for (i=0; i<document.forms[0][tree[j][2]].length; i++) //go through each
{
document.forms[0][tree[j][2]].checked = status; //change each
//alert(&quot;[SC]Info About Box Being Checked\n Value:&quot; + document.forms[0][tree[j][2]].value + &quot;\nName:&quot; + document.forms[0][tree[j][2]].name + &quot;\nChecked:&quot; + document.forms[0][tree[j][2]].checked + &quot;\ntype:&quot; + document.forms[0][tree[j][2]].type + &quot;\nLabel:&quot; + document.forms[0][tree[j][2]].label + &quot;\nNext to Be Checked:&quot; + tree[j][0]+&quot;,&quot;+tree[j][1] + &quot;\nCurrent Head\\Left:&quot; + tree[j][3]+&quot;,&quot;+tree[j][4]+ &quot;\nName Looked For:&quot; + tree[j][2]);
}
}
else
{
document.forms[0][tree[j][2]].checked = status; //if single change.
//alert(&quot;[SC]Info About Box Being Checked\nValue:&quot; + document.forms[0][tree[j][2]].value + &quot;\nName:&quot; + document.forms[0][tree[j][2]].name + &quot;\nChecked:&quot; + document.forms[0][tree[j][2]].checked + &quot;\ntype:&quot; + document.forms[0][tree[j][2]].type + &quot;\nLabel:&quot; + document.forms[0][tree[j][2]].label + &quot;\nNext to Be Checked:&quot; + tree[j][0]+&quot;,&quot;+tree[j][1] + &quot;\nCurrent Head\\Left:&quot; + tree[j][3]+&quot;,&quot;+tree[j][4]+ &quot;\nName Looked For:&quot; + tree[j][2]);
}
<% end if %>
Cstacklev += 1;
ShowChild(tree[j][0],tree[j][1], status); //resubmit's its own for it's children
Cstacklev -= 1;
}
}
//alert(&quot;[SC]Finished Stack Level : &quot; + Cstacklev);
}

function ShowParent(HP, LP) //HP/LP IDs being looked for as current then it's parent is submited
{
for(var j=0; j<=max; j++) //from 0 index to max recorded rows
{
if ((tree[j][0] == HP) && (tree[j][1] == LP)) // if ID matches HP/LP
{

<% if instr(ucase(Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;)), &quot;MSIE&quot;) <> 0 then %>
if (document.all(tree[j][2]).length > 1) // if multiple control w/ same name
{
for (i=0; i<document.all(tree[j][2]).length; i++) //loop through each
{

var str1 = document.all(tree[j][2],i).label;
var str2 = tree[j][5];
if (str1.toLowerCase() == str2.toLowerCase())
{ //if current control matches the label for the &quot;True&quot; parent
document.all(tree[j][2],i).checked = true;
}
}
}
else //if there is only one control with that name
{
document.all(tree[j][2],0).checked = true;
}
<% else %>
/*
if (document.forms[0][tree[j][2]].length > 1) // if multiple control w/ same name
{
for (i=0; i<document.forms[0][tree[j][2]].length; i++) //loop through each
{
var str1 = document.forms[0][tree[j][2]].label;
var str2 = tree[j][5];
if (str1.toLowerCase() == str2.toLowerCase())
{ //if current control matches the label for the &quot;True&quot; parent
document.forms[0][tree[j][2]].checked = true;
alert(&quot;[SP]Info About Box Being Checked\nValue:&quot; + document.forms[0][tree[j][2]].value + &quot;\nName:&quot; + document.forms[0][tree[j][2]].name + &quot;\nChecked:&quot; + document.forms[0][tree[j][2]].checked + &quot;\ntype:&quot; + document.forms[0][tree[j][2]].type + &quot;\nLabel:&quot; + document.forms[0][tree[j][2]].label+ &quot;\nNext to Be Checked:&quot; + tree[j][3]+&quot;,&quot;+tree[j][4] + &quot;\nCurrent Head\\Left:&quot; + tree[j][0]+&quot;,&quot;+tree[j][1]+ &quot;\nName Looked For:&quot; + tree[j][2]);
}
}
}
else //if there is only one control with that name
{
document.forms[0][tree[j][2]].checked = true;
alert(&quot;[SP]Info About Box Being Checked\n Value:&quot; + document.forms[0][tree[j][2]].value + &quot;\nName:&quot; + document.forms[0][tree[j][2]].name + &quot;\nChecked:&quot; + document.forms[0][tree[j][2]].checked + &quot;\ntype:&quot; + document.forms[0][tree[j][2]].type + &quot;\nLabel:&quot; + document.forms[0][tree[j][2]].label + &quot;\nNext to Be Checked:&quot; + tree[j][3]+&quot;,&quot;+tree[j][4]+ &quot;\nCurrent Head\\Left:&quot; + tree[j][0]+&quot;,&quot;+tree[j][1] + &quot;\nName Looked For:&quot; + tree[j][2]);
}*/
<% end if %>
Pstacklev += 1;
ShowParent(tree[j][3],tree[j][4]); //continue to search by submiting parent of current
Pstacklev -= 1;
}
}
//alert(&quot;[SP]Finished Stack Level : &quot; + Pstacklev);
}
[/tt]

and here is the lines that create the names, and &quot;Label&quot; so to speak.


[tt]
if Pname = &quot;&quot; then 'will be modified when we need to find parents of children
HTMLStr = HTMLStr & writetabs(Spaces) & vbcrlf & &quot;<input onclick=&quot;&quot;javascript:ShowChild(&quot; & TheObj(HID,j) & &quot;,&quot; & TheObj(LID,j) & &quot;,this.checked)&quot;&quot; type=&quot;&quot;&quot; & TheObj(RType, j) & &quot;&quot;&quot; name=&quot;&quot;&quot; & TheObj(Name, j) & &quot;&quot;&quot; value=&quot;&quot;&quot; & TheObj(Value,j) & &quot;&quot;&quot; label=&quot;&quot;&quot; & TheObj(Label, j)& &quot;&quot;&quot;>&quot;
else
HTMLStr = HTMLStr & writetabs(Spaces) & vbcrlf & &quot;<input onclick=&quot;&quot;javascript:ShowParent(&quot; & TheObj(HP,j) & &quot;,&quot; & TheObj(LP,j) & &quot;); ShowChild(&quot; & TheObj(HID,j) & &quot;,&quot; & TheObj(LID,j) & &quot;,this.checked);&quot;&quot; type=&quot;&quot;&quot; & TheObj(RType, j) & &quot;&quot;&quot; name=&quot;&quot;&quot; & TheObj(Name, j) & &quot;&quot;&quot; value=&quot;&quot;&quot; & TheObj(Value,j) & &quot;&quot;&quot; label=&quot;&quot;&quot; & TheObj(Label, j)& &quot;&quot;&quot;>&quot;
end if
[/tt]

ok now that you've seen functions, now what, and yes they both should behave pretty much the same, If i say I want checkbox &quot;5&quot; to be checked, both IE and NS should do this &quot;simple&quot; task. I am not talking about anything on complex level, as you can see from both ShowChild and ShowParent, the IE and NS are the same, other than the way they reach the checkboxes (IE = document.all , NS = document.forms)

to put it frankly I hate NS, most of my projects are extended by hours just to make then NS friendly especially with the damn limitations that netscape has ont he client side. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
I will be glad to look at it in-depth when I have some time today or tomorrow. Looks like a nice piece of code.

A tip: when you see your code appear in italics, that's because you used '[i...' somewhere and didn't unlick the 'Process TGML' checkbox when submitting. Please post again. If you don't unclick 'Process TGML' you can instead put
Code:
tags around your code. [sig][/sig]
 
hmm good point, I didnt catch that. I may repost, if it doesnt look right (or if you look for a i loop) [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top