Lost in a JavaScript For Loop

I am lost in a JavaScript For Loop !! Can someone help me please. Here is my code:

var stringlength = frm.titleInfo.value.length;

FOR LOOP IN HERE

FOR (indexofcolon<=stringlength)

{

indexofsemi = frm.titleInfo.value.indexOf(“;”,indexofsemi+1);

element = frm.titleInfo.value.substring(indexofcolon,indexofsemi);

indexofcolon = frm.titleInfo.value.indexOf(“:”,indexofcolon+1);

name = frm.titleInfo.value.substring(indexofsemi+1,indexofcolon);

doc.getElementById(element).title = name;

}

I have a long string that finishes with a colon. I collect the index of the colon in my code. What I want is the code to loop until the value of indexofcolon equals the string length. Can someone amend my code please. I have looked in the book but am more of a lotusscript man.

Thanks

Paul

Subject: lost in a JavaScript For Loop

That’s not a “for”, even if you typed the word for in there yourself – it’s a “while”. A for uses a fixed number of iterations, as:

for (;;) {

code

}

like this:

for (i=1;i<=string.length();i++) {

alert(‘Still counting’);

}

alert(‘Finished counting’);

Every time the code runs, the value of the counter i is incremented. The code will run unless the condition returns false. A “while”, on the other hand, only tests a condition – it doesn’t use a counter to control the iterations.

Subject: IndexOf returns -1 when the string is not found. -1 will always be less that the length of the string.