|
This tutorial will explain to you how to create a simple PM messageRepostable, NOT EDITABLEPreview: HereCreator: Krayzie10291Level:Semi Novice-IntermediateRequirements:- A basic understanding of HTML
- A basic understanding of JavaScript(basics)
- A basic understanding of innerHTML
- Some RegExp(Tutorial)
Table of Contents:- Starting Out
- The Variable
- The if() Statement
- The else if() Statement
- The else Statement
- Ending
- What Your Code Should Look Like
Starting Out:<script>This tells the browser you are starting a script. The Variable:var pm_td = document.getElementsByTagName("td");This will grab every single td(table cell) tag in the entire document. pm_td, that can be anything, pm, td, anything! The if() Statement:if(pm_td[2].innerHTML.match(/,\s0\sa/i)) document.write("You have no new PM\'s"); (You must put a "\" in front of the " ' " because it is a Regular Expression, and will cause a SYNTAX ERROR) if(pm_td[2].innerHTML.match(/,\s0\sa/i)) That makes sure that there are 0 PM messages on the page. To get more in dept, it searches for ", 0 " with the spaces(\s is a space in RegExp). That is located in the message, "Hey, X you have X messages, X are new". The X are new is what the if() statement is looking for, if X=0 then it will display: You have no new PM'sThe else if() Statement:else if(pm_td[2].innerHTML.match(/Welcome Guest/i)) document.write("Please <a href='/index.cgi?action=login'>Login</a> or <a href='/index.cgi?action=register'>Register</a>");This searches through the same "Hey X" string, except this time it searches for "Welcome Guest", which appears when you're not logged in, and displays: Please Login or RegisterThe else Statement:else document.write("You have new PM\'s");(Once again place an "\" before the " ' " to avoid the ERROR) This string writes You have new PM's if the first two statements above aren't true. Ending:</script>IMPORTANT: Always remember to add that to the end of your script to avoid you know what( ERROR). What Your Code Should Look Like: <script> var pm_td = document.getElementsByTagName("td"); if(pm_td[2].innerHTML.match(/,\s0\sa/i)) { document.write("You Have No New Messages"); else if(pm_td[2].innerHTML.match(/Welcome Guest/i)) { document.write("Please <a href='/index.cgi?action=login'>Login</a> or <a href='/index.cgi?action=register'>Register</a>"); else document.write("You have new PM\'s"); </script>
That is the simple version of what it should look like. Feel free to edit the code freely. Try centering it, and making it into a table, even try attaching it to the Navigation Bar. ~ THE END
Last Edit: Oct 31, 2005 18:40:26 GMT by /^(Krayzie)?$/i
|
|
|
|