Post by Peter on Jun 18, 2004 11:46:33 GMT
Using the Split Function
The split function can be used somewhat like the RegExp. You use it to obtain data from something. It’s somewhat hard to explain, but I’ll do my best.
The split functions takes an area (document, TD’s, forms) and takes data from it. What you do is you split apart the area by a tag or word or character or punctuation mark in the area. The split apart areas are then placed in an array. [0] is what is before what you split by, [1] is the area after what you split by, and so on and so forth. I’m going to use the split function to access the person’s username.
This part is accessing the third TD in a variable name wTD:
This part is checking to see if the person is logged in by seeing if the text that appears when someone is logged in is there:
This part is splitting apart the html inside of the TD and putting it into an array by “Hey,”. Since I used the [1] it is the part after “Hey,”.
This part is splitting the variable(array[1]) by a comma and putting it into an array. Since I gave it the [0] it is the part before the comma. So we now have accessed the persons username with the part after “Hey,” and the part before the first “,”.
This part is simply writing a welcome message with the persons username.
The split function can be used somewhat like the RegExp. You use it to obtain data from something. It’s somewhat hard to explain, but I’ll do my best.
The split functions takes an area (document, TD’s, forms) and takes data from it. What you do is you split apart the area by a tag or word or character or punctuation mark in the area. The split apart areas are then placed in an array. [0] is what is before what you split by, [1] is the area after what you split by, and so on and so forth. I’m going to use the split function to access the person’s username.
<script>
<!--
var wTD = document.getElementsByTagName(‘td’)[2]
if(wTD.innerHTML.match(/Hey,/i)){
var name = wTD.innerHTML.split(‘Hey, ’)[1];
name = name.split(‘,’)[0]
document.write(“<font size=3>Welcome to the forum, “+name+”.</font>”);
}
-->
</script>
This part is accessing the third TD in a variable name wTD:
var wTD = document.getElementsByTagName(‘td’)[2]
This part is checking to see if the person is logged in by seeing if the text that appears when someone is logged in is there:
if(wTD.innerHTML.match(/Hey,/i)){
This part is splitting apart the html inside of the TD and putting it into an array by “Hey,”. Since I used the [1] it is the part after “Hey,”.
var name = wTD.innerHTML.split(‘Hey,’)[1];
This part is splitting the variable(array[1]) by a comma and putting it into an array. Since I gave it the [0] it is the part before the comma. So we now have accessed the persons username with the part after “Hey,” and the part before the first “,”.
name = name.split(‘,’)[0]
This part is simply writing a welcome message with the persons username.
document.write(“<font size=3>Welcome to the forum, “+name+”.</font>”);
Tutorial By: Forte