Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Feb 8, 2010 16:24:02 GMT -8
Ok so i created a script that, for starters, will make a table in any sig that have tableii placed in the sig. In this table i placed one table row, and 2 columns. The first column has a picture, and the 2nd column has nothing in it. When i click on the picture(in the first column), i made another script run. This creates another table in the 2nd column of the first table I placed one row and one column for now in the 2nd table. Created a textNode "dname (uname)" (<something like that) And then the script changes dname into your displayname and uname into your username And it works great, except i do not know, and cannot find out how to make it appear in ONLY the sig i clicked the picture in Like, i have 3 posts(sigs) all with this table in it. and when i click on one of them. The, "dname (uname)" appears 3 times in the last post(sig). Now if theres only one it works great. But Thats not what im aiming at. Basically what im trying to do is, If you click on the picture in the sig, then in ONLY that sig will the script run. And i have no idea how to make that happen. here's what i got header <script type="text/javascript"> //By Topeka //Global Header
function showtable() {
/* for (sig=document.getElementsByTagName('font'), x=0; x<sig.length; x++){ if (sig[x].size=="1" && sig[x].innerHTML.match("tableii") && sig[x].innerHTML.match("test")){ sig[x].getElementsByTagName('td')[1].innerHTML=""; }
else { */
if (location.href.match(/ion=(display|viewprofile)/)) { for (tables=document.getElementsByTagName('table'), a=0; a<tables.length; a++) { if (tables[a].cellPadding=="4" && tables[a].cellSpacing=="1" && tables[a].width=="100%") { for (trs=tables[a].getElementsByTagName('tr'), b=0; b<trs.length; b++) {
//this is in sig for (sig=trs[b].getElementsByTagName('font'), c=0; c<sig.length; c++) { if (sig[c].size=="1" && sig[c].innerHTML.match("tableii")) {
var tbl1 = document.createElement('table'); var tblbody1 = document.createElement('tbody');
var row1 = document.createElement('tr'); var cell1 = document.createElement('td'); var cell1txt = document.createTextNode("dname (nameu)");
//append into table cell1.appendChild(cell1txt); row1.appendChild(cell1); tblbody1.appendChild(row1); tbl1.appendChild(tblbody1);
//main table append inner table cellmain2.appendChild(tbl1);
//set attributes tbl1.setAttribute("border", "1");
//main table attributes cellmain2.setAttribute("background", "http://i285.photobucket.com/albums/ll47/musicgodguy/brians/Site%20images/50_Opacity.png")
//this will end the for each sig } }
//find in mini profile for (tds=trs[b].getElementsByTagName('td'), d=0; d<tds.length; d++) { if (tds[d].vAlign=="top" && tds[d].width=="20%" && tds[d].className.match(/windowbg/)) {
//displayname nameb=tds[d].getElementsByTagName('b')[0]; //username usrname=tds[d].getElementsByTagName('b')[0].getElementsByTagName('a')[0].href.split('user=')[1];
//replace into table for (sig=trs[b].getElementsByTagName('font'), z=0; z<sig.length; z++) { if (sig[z].size=="1" && sig[z].innerHTML.match(/tableii/)) { //displayname sig[z].innerHTML=sig[z].innerHTML.replace("dname",nameb.innerHTML); //username sig[z].innerHTML=sig[z].innerHTML.replace("nameu",usrname);
//end repalcing table } } //end find mini profile } }
//end the entire table } } } }
/* //end else }
//end 1 before else
} */
//end function } </script>
footer <script type="text/javascript"> //By Topeka //Global Footer
for (sig=document.getElementsByTagName('font'), z=0; z<sig.length; z++) { if (sig[z].size=="1" && sig[z].innerHTML.match("tableii")) {
//main table Elements var tblmain = document.createElement('table'); var tblmainbody = document.createElement('tbody');
var rowmain = document.createElement('tr');
var cellmain1 = document.createElement('td'); var cellmaintxt1= document.createElement('img');
var cellmain2 = document.createElement('td');
//main table appends start cellmain1.appendChild(cellmaintxt1)
rowmain.appendChild(cellmain1) rowmain.appendChild(cellmain2)
tblmainbody.appendChild(rowmain) tblmain.appendChild(tblmainbody) sig[z].appendChild(tblmain)
//main table attributes // cellmain2.setAttribute("background", "http://i285.photobucket.com/albums/ll47/musicgodguy/brians/Site%20images/50_Opacity.png") tblmain.setAttribute("border","0") cellmaintxt1.setAttribute("src","http://i285.photobucket.com/albums/ll47/musicgodguy/brians/Sigs/MiniProfilepiciii.png") cellmaintxt1.onclick= function() { showtable(); }; //top table enders } }
</script>
You can also see in the header that i was trying to make it if you click the picture again, the table will go away, but i havent really looked at whats going wrong, i got it to work before(smallerscale), but its messing up now. If you can help w/ that too, that would be great. uh.. i got a preview i guess of what is happening. topekat2.proboards.com/index.cgi?board=general&action=display&thread=2I think guests can see everything, if not let me know.
|
|
|
Post by Wormopolis on Feb 9, 2010 0:22:59 GMT -8
rather then scanning the page for all the different signature fields, why not send the object you just clicked to the show function.
then in the show function, since it will be a passed parameter, you can have it affect its nextSibling or whatever directly.
to call:
onclick=showtable(this)
the function:
function showtable(clickedimage) { clickedimage.parentNode.nextSibling.innerHTML="dname (uname)" }
I dont know if that is the actual relation to where you want the ntext to show up, you have to traverse to it. but image object is transferred as a variable to the function, and therefore you can treat it like a object again iIN the function.
does that make sense?
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Feb 9, 2010 15:16:22 GMT -8
uh. i think so. I'll try it out and see if i can get it, ill edit or repost. The only problem i have is, What is
showtable( this ) What is 'this'?
i see it in alot of scripts like "this.blah blah; this.dosomething" and i can never find what it means. Like i can take a good guess. as like its calling the object that is running the 'onclick', but its just a guess and i can never found out what 'this' really means.
|
|
|
Post by Wormopolis on Feb 9, 2010 16:00:27 GMT -8
when a function is an event that is declared ON an object, then the keyword "this" refers to the object itself.
so lets say you had an image that you wanted to hide if they clicked it, you would:
myImage.onclick=function() {this.style.display='none';}
this is a reserved word in javascript. another example, look at dangerkarts profile on this site. see the little running guy he has as an avatar? try to put your mouse over him.
when you send an object as a parameter of a function, you can access that object within the function. That gives you reusability of the function on multiple objects. every object will call the same function, and every object will send a reference to itself to the function for it to process.
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Feb 9, 2010 19:23:14 GMT -8
ah i see. this will help very much. (no i didnt mean for the play on words -.- lol) But i do understand what you are saying. Also i got the script to work, and i made the appear and disappear to work too. so i got two birds with one stone. Thanks for the help. little by little i learn more about how all of this works, so thanks.
I do have one last question though. By placing the function into the footer like this. Will it cause any problems in the script? I plan on assigning all the variables of the miniprofile, then my plan was to hide the entire miniprofile on the left side. whether it will work the way im thinking it is a different story, but i just wanna make sure doing that wont mess it up.
Heres the working script for above
<script type="text/javascript"> //By Topeka //Global Footer
for (sig=document.getElementsByTagName('font'), z=0; z<sig.length; z++) { if (sig[z].size=="1" && sig[z].innerHTML.match("tableii")) {
//main table Elements var tblmain = document.createElement('table'); var tblmainbody = document.createElement('tbody');
var rowmain = document.createElement('tr');
var cellmain1 = document.createElement('td'); var cellmaintxt1= document.createElement('img');
var cellmain2 = document.createElement('td');
//main table appends start cellmain1.appendChild(cellmaintxt1)
rowmain.appendChild(cellmain1) rowmain.appendChild(cellmain2)
tblmainbody.appendChild(rowmain) tblmain.appendChild(tblmainbody) sig[z].appendChild(tblmain)
//main table attributes // cellmain2.setAttribute("background", "http://i285.photobucket.com/albums/ll47/musicgodguy/brians/Site%20images/50_Opacity.png") tblmain.setAttribute("border","0") cellmaintxt1.setAttribute("src","http://i285.photobucket.com/albums/ll47/musicgodguy/brians/Sigs/MiniProfilepiciii.png") cellmaintxt1.onclick= function() { showtable(this); };
//try function showtable(clickedimage) {
if (clickedimage.parentNode.nextSibling.innerHTML.match(/loop/)){ clickedimage.parentNode.nextSibling.innerHTML=""; }
else{ clickedimage.parentNode.nextSibling.innerHTML="dname (uname)loop";
//rethink below. parent nodes from clickedimage and nextChilds
//below will take you to the td of your miniprofile
miniprofile=clickedimage.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.firstChild;
disname=miniprofile.getElementsByTagName('b')[0]; usrname=miniprofile.getElementsByTagName('b')[0].getElementsByTagName('a')[0].href.split('user=')[1];
//this takes you to your part of the table in the sig //tdsig=clickedimage.parentNode.nextSibling.innerHTML;
rplarea=clickedimage.parentNode.nextSibling;
rplarea.innerHTML=rplarea.innerHTML.replace("dname",disname.innerHTML); rplarea.innerHTML=rplarea.innerHTML.replace("uname",usrname);
//else end }
//function end } //try
//top table enders } }
</script>
Thanks again for you help.
|
|
|
Post by Wormopolis on Feb 9, 2010 20:24:59 GMT -8
it will need to be in the footer anyways since it has to run after all the content has been posted to the page.
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Feb 10, 2010 12:31:17 GMT -8
Ok cool. Thanks wormo
|
|