NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 4, 2012 20:01:45 GMT -8
This is my first code. I made it from scratch. I've got everything worked out but how to call the array variables. Wormo, help please! Once it is complete I'll submit it to the Code Database on Support.
<script type="text/javascript"> <!-- //Create Header from Board //by NetMaster
var titles =[ ["Anti Welcome Board","Welcome to our Forum Spill"], ["Welcome Board","Welcome to our Forum Spill"] ];
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ if(awaytd.innerHTML.match(/'+titles+'/g) && awaytd.className=='windowbg2') { awaytd.style.display="none"; awaytd[i+1].style.display="none"; awaytd[i+2].style.display="none"; awaytd[i+3].style.display="none"; awaytd[i-1].colSpan="5"; awaytd[i-1].innerHTML='+titles[i+1]+'; } } } --> </script>
|
|
|
Post by Wormopolis on Jan 4, 2012 20:21:44 GMT -8
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 4, 2012 21:00:18 GMT -8
Sort of, except my version allows them to inject their own HTML instead of the Board Title.
|
|
|
Post by Wormopolis on Jan 5, 2012 0:15:58 GMT -8
well you have the array defined all wrong to start
if you declare it as new Array(), then you would have to put in elements like
titles[0]='thing';
but since you want to do a multi-dimensional array you will want to use the more classic form
titles=[ [one, two], [three, four] ];
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 5, 2012 5:06:13 GMT -8
Okay changed it in the first post.
|
|
|
Post by Wormopolis on Jan 5, 2012 20:49:44 GMT -8
to access arrays, you need to use indices. titles.firstchild.value doesnt mean anything because titles isnt an XML object with a firstchild.
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 6, 2012 10:26:51 GMT -8
Okay. Do I need to include a new variable that runs a for statement for titles?
var match = for(i=0;i<=titles.length;i++) { titles };
|
|
|
Post by Wormopolis on Jan 6, 2012 17:19:18 GMT -8
that line doesnt make any sense.
you need to have multiple indices if you are accessing multi-dimensional arrays.
apple[1][3]
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 7, 2012 7:05:15 GMT -8
Okay in this line here
if(awaytd.innerHTML.match(/'+titles+'/g) && awaytd.className=='windowbg2') {
I'm trying to get it to search through the array and match an entry to the innerHTML, but I don't have the right syntax: '+titles+' Doesn't work.
|
|
|
Post by Wormopolis on Jan 7, 2012 11:06:18 GMT -8
because titles in a multidimensional array. see my post above
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 7, 2012 16:57:38 GMT -8
Okay I am thinking a new way of set up for the multi-dimensional array so I can call all first entries only
<script type="text/javascript"> <!-- //Create Header from Board //by NetMaster
title[0] = new Array("Anti Welcome Board", "This is the welcome to our forum part"); title[1] = new Array("Other Board","Other board info");
var titles = for(i=0;i<title.length;i++){title[0]}; var info = for(i=0;i<title.length;i++){title[1]};
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ if(awaytd.innerHTML.match(/titles/g) && awaytd.className=='windowbg2') { awaytd.style.display="none"; awaytd[i+1].style.display="none"; awaytd[i+2].style.display="none"; awaytd[i+3].style.display="none"; awaytd[i-1].colSpan="5"; awaytd[i-1].innerHTML=info; } } } --> </script>
|
|
|
Post by Wormopolis on Jan 8, 2012 2:53:39 GMT -8
syntax error. i was not defined when you tried to access the multidimensional array of "title" to put values in "titles" and "info"
you cant really access dimensions of arrays like you are wanting. if you want to extract all the [0] entires from each entry in the array, you would need to do that with a for loop and a new array.
what you have in the first post is going to get you closer then what you just posted
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 8, 2012 6:22:49 GMT -8
<script type="text/javascript"> <!-- //Create Header from Board //by NetMaster
var titles =[ ["Anti Welcome Board","Welcome to our Forum Spill"], ["Welcome Board","Welcome to our Forum Spill"] ];
var rgx=new RegExp(titles[0],'g'); var rgx2=new RegExp(titles[1],'g');
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ if(awaytd.innerHTML.match(/'+rgx+'/g) && awaytd.className=='windowbg2') { awaytd.style.display="none"; awaytd[i+1].style.display="none"; awaytd[i+2].style.display="none"; awaytd[i+3].style.display="none"; awaytd[i-1].colSpan="5"; awaytd[i-1].innerHTML='+rgx2+'; } } } --> </script>
|
|
|
Post by Wormopolis on Jan 8, 2012 21:22:50 GMT -8
cant do regexp like
match(/'+titles[0]+'/g)
to do that, you will need to create a regexp object
var rgx=new RegExp(titles[0],'g');
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 9, 2012 7:18:30 GMT -8
<script type="text/javascript"> <!-- //Create Header from Board //by NetMaster
var titles =[ ["Anti Welcome Board","Welcome to our Forum Spill"], ["Welcome Board","Welcome to our Forum Spill"] ];
var rgx=new RegExp(titles[0],'g'); var rgx2=new RegExp(titles[1],'g');
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ if(awaytd.innerHTML.match(/'+rgx+'/g) && awaytd.className=='windowbg2') { awaytd.style.display="none"; awaytd[i+1].style.display="none"; awaytd[i+2].style.display="none"; awaytd[i+3].style.display="none"; awaytd[i-1].colSpan="5"; awaytd[i-1].innerHTML='+rgx2+'; } } } --> </script>
I also tried this line:
if(rgx.test(awaytd.innerHTML) == 'true' && awaytd.className=='windowbg2')
instead of the
if(awaytd.innerHTML.match(/'+rgx+'/g) && awaytd.className=='windowbg2')
|
|