|
Post by Wormopolis on Jan 9, 2012 19:31:11 GMT -8
2 problems with what you have. you keep thinking that "i" will stay defined later in the code. in your 2 rgx lines, you call on "i" and it isnt defined anywhere. both of those would need to be inside the for loop in order for "i" to have a value
since rgx is a regexp object, you can run a match or test directly on it. this doesnt evaluate:
.match(/'+rgx+'/g)
this would
.match(rgx)
and why do you even need rgx2?
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 10, 2012 6:57:58 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 2"] ];
for(i=0;i<titles.length;i++){ 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) && 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>
["Anti Welcome Board","Welcome to our Forum Spill"], ["Welcome Board","Welcome to our Forum Spill 2"] ];
I want it to find "Anti Welcome Board" and then insert "Welcome to our Forum Spill" as the innerHTML of the cell.
Then when it finds Welcome Board it should insert "Welcome to our Forum Spill 2"
rgx is the first part, finding the existing entry rgx2 is the replacement text/html
I also tried it this way:
var rgx=new RegExp(for(i=0;i<titles.length;i++){titles[0],'g'}); var rgx2=new RegExp(for(i=0;i<titles.length;i++){titles[1],'g'});
|
|
|
Post by Wormopolis on Jan 10, 2012 17:37:26 GMT -8
rgx2 ISNT replacement text you defined it as a regexp. that isnt what regexp is for. regexp is for pattern matching. rgx, the way you are using it, is correct, however....
tell me what the value of rgx will be after it runs that first loop?
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 10, 2012 18:15:56 GMT -8
1 less than the length of titles. Need <=
<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 2"] ];
var rgx=new RegExp(for(i=0;i<titles.length;i++){titles[0],'g'}); var replace=for(i=0;i<titles.length;i++){titles[1],'g'}; }
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ if(awaytd.innerHTML.match(rgx) && 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=replace; } } } --> </script>
|
|
|
Post by Wormopolis on Jan 10, 2012 18:55:06 GMT -8
rgx is just a single variable. after the first loop is done, its going to be the last value it ever gets set to.
it would similar to this:
for (i=0; i<10; i++) { j=i; }
at the end of that loop, j ISNT 0 through 9. its 9. JUST 9.
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 11, 2012 7:34:37 GMT -8
So move the (for) loop inside of the regx so regx is now every instance of titles instead of the last one. Or use a while loop instead?
<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 2"] ];
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td'); var x=0; while(awaytd[++x]){i=0; while(titles[++i]){if(awaytd[x].innerHTML==titles[0] && awaytd[x].className =='windowbg2'){ awaytd[x].style.display="none"; awaytd[x+1].style.display="none"; awaytd[x+2].style.display="none"; awaytd[x+3].style.display="none"; awaytd[x-1].colSpan="5"; awaytd[x-1].innerHTML=n[1]; break; } } } } --> </script>
|
|
|
Post by Wormopolis on Jan 11, 2012 21:07:48 GMT -8
I would definately stay away from while loops until you are more comfortable with for loops. whle loops, if done wrong, will lock up your board with an infinite script.
you need to move the rgx variable to inside the for loop, so that every iteration of "i" redefines it.
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 12, 2012 5:27:26 GMT -8
Okay so back to here:
<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 2"] ];
for(i=0;i<titles.length;i++){ var rgx=new RegExp(titles[0],'g'); var replace=titles[1]; }
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ if(awaytd.innerHTML.match(rgx) && 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=replace; } } } --> </script>
|
|
|
Post by Wormopolis on Jan 12, 2012 22:01:24 GMT -8
nope. I was steering you AWAY from that. you only need ONE for loop in this code.
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 13, 2012 11:41:31 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 2"] ];
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ var rgx=new RegExp(titles[0],'g'); var replace=titles[1]; if(awaytd.innerHTML.match(rgx) && 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=replace; } } } --> </script>
|
|
|
Post by Wormopolis on Jan 13, 2012 16:23:50 GMT -8
the --> at the end needs a // in front of it...
and if you run that code.. what happens?
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 14, 2012 6:48:03 GMT -8
Nothing.
|
|
|
Post by Wormopolis on Jan 14, 2012 23:34:40 GMT -8
bah... I just realized the array would need to be indexed for this to work. you WILL need 2 for loops. but the second one will need to be inside the first one.
for i= (cells) for j= (array elements) rgx= array[j][0] stuff next j next i
|
|
NetMaster
Code Helper
"Get caught in my web!"
Posts: 305
NetMaster said 0 great things
|
Post by NetMaster on Jan 19, 2012 16:36:13 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 2"] ];
if(pb_action == 'home'){ var awaytd = document.getElementsByTagName('td');
for(i=0;i<awaytd.length;i++){ for(j=0;j<titles.length;j++){ var rgx=new RegExp(titles[j][0],'g'); var replace=titles[j][1]; if(awaytd.innerHTML.match(rgx) && 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=replace; } } } } --> </script>
And it works! Thanks Wormo for walking me through this. I thought that two different variables for td.length and titles.length would be needed.
Now time to figure out another code to try and write.
|
|
|
Post by Wormopolis on Jan 19, 2012 17:23:41 GMT -8
hopefully you learned a lot on this one
|
|