[thelist] JavaScript Trauma
kev.skindrill
kev.skindrill at bigfoot.com
Mon Mar 20 16:40:59 2000
Hullo all
Firstly, may I thank those of you who responded to my
introduction last week & made me feel so welcome. Steve said you were a nice
bunch & I have to agree.
I am appealing for some help from you all. Having (I hope)
mastered HTML I am currently learning JavaScript which is proving to be a
bit more difficult. As I mentioned last week I am learning from the HTML
Goodies site & books which, thus far, have been easy to understand. However,
I just can't seem to get my head round 'substring' and 'indexOf()'. Below is
a sample of an assignment from the book.
function TheSeconds()
{
var SecCounts = StartTheCount();
var SecCounts1 = ""+SecCounts;
SecCounts1= SecCounts1.substring(0,SecCounts1.indexOf(".")) + " seconds";
if (DifferenceInSeconds >= 6)
{alert("done")}
else
{
document.FormCount.CountBox.value = SecCounts1
window.setTimeout('TheSeconds()',1000);}
}
In case of confusion, 'StartTheCount()' refers to another function in the script. Apparently indexOf() is a "command that returns a count of what you point it towards. In this case, we have pointed it toward the results of the first script." ( this is what it says in the book). What I don't understand is why there is an "." in the brackets of 'indexOf()'. The whole script can be viewed at
www.htmlgoodies.com/JSBook/lesson43example.html
As I said, I also don't understand the 'substring' thing either. Here is another example of a script, this time for a scrolling text.
function ScrollAlong()
{
temp = scr.substring(0,1);
scr += temp
scr = scr.substring(1,scr.length);
document.Scroll.ScrollBox.value = scr.substring(0,55);
counts = setTimeout("ScrollAlong()",50);
}
Please could someone explain to me the relevance fo the 2 numbers in the brackets after 'substring'. The explanation in the book is "The 'substring()' returns a portion, or sub, of a text string depending on an index. The index is contained within the instance, zero and one." This means absolutely n
othing
to me. I haven't had this much trouble with the rest of the book, I would
be interested if anyone who knows JS thinks that this is a poor explanation.
The rest of the script can be viewed at
www.htmlgoodies.com/JSBook/lesson42example.html
Sorry this is such a long mail, but I hope I have explained my
problem sufficiently. I would love a better explanation of these 2 items if
anyone could point me in the direction of a site that they learnt JS from or
one they have heard recommended.
Ta ever so.
Clown Love
kev.skindrill@bigfoot.com
www.skindrill.freeserve.co.uk