Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 10, 2010 14:36:02 GMT -8
i think it would be better if i did this on a thread instead of by pm so lets pick up were we left off
also how do you test codes on threads and not boards?
|
|
|
Post by Wormopolis on Jun 10, 2010 15:38:50 GMT -8
when I say generate HTML, I mean you are literally typing HTML into the script. you either store it in a variable or directly edit some element's innerHTML attribute. you can also directly write HTML to the dcoument using document.write().
so lets say you were writing a code to place somewhere on the page, a table with links in it. you would make a variable to hold the HTML that it takes to make that table:
var nwTbl="<table width='92%'><tr><td><br><a href='URL1'>Link 1</a><br><a href='URL2'>Link 2</a><br><a href='URL3'>Link 3</a><br></td></tr></table>";
notice how it is all HTML in there (you can also insert in other javascript variables, but that is another lesson). now in our code instructions, we told the user that they need to insert somewhere into their own page a div with id="linktable". they could put it into a side table, they could put it in the main header so it appears above the forum, they could put it in main footer so it appears below the forum.. wherever. as long as they have <div id="linktable"></div> somewhere
what we are aiming to do, is put that HTML we generated INSIDE that div for them. so we simply check to make sure the div exists:
if (document.getElementById('linktable'))
(if it doesnt, then the code moves on and they come back saying they dont see anything on the page, at which point we look at their source and tell them they forgot to make the div like they were told to do)
if it DOES exist, then we modify the innerHTML of that element by setting it to the variable we made:
if (document.getElementById('linktable')) document.getElementById('linktable').innerHTML=nwtbl;
then the HTML we wrote will now appear inside. There is a caveat to all this however. The div they made MUST appear BEFORE this code tries to run or it will never work. so lets say they are using left&right side tables. and they put this code into main footer. they put the DIV into the right side tables. the code will try to run BEFORE the div is ever even made and fail everytime. if that is the case, then the code would need to be moved to global footers. if they only want to have the link table appear when looking at main page, a location check would have to be done:
if (pb_action=='home') { code }
as to your second question, The way you do that is why you saw a BUNCH of codes in my source that are duplicates of each other or dont seem to run. when I am showing previews of things, I like to keep as much on this site as possible. so if you look at my source, you will notce a bunch of codes have things like
if (location.href.match(/nobanrem/)) { code }
that means that in order for that code to run at all, the word "nobanrem" must appear up in the URL for the site. if it doesnt, the whole code gets skipped. if I added &nobanrem to the end of the URL, then the banner remodel code wouldnt run that page load.
its the same thing when I make certain threads have codes work while others dont. Lets say someone wanted a thread remodel (like eveready). I want him to be able to see my progress on the thread we are discussing the code in, without it affectiong other threads in request. in the board footer, I have the code but I surround it with if (location.href.match(/thread=NUM/)) { code }
where NUM is the thread id. like the thread id for THIS thread is 595. you can see it in the URL right now. another example is the affiliate table code that you just finished. if you scroll down to the bottom, you will see the bumpercars test I was doing.. but only in THAt thread.
make more sense?
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 11, 2010 4:00:11 GMT -8
the second part did....could you post the whole html code and then the div and let me try it because i can't seem to get it to work. Like take the table you made and add all the other stuff you need and let me play with it.
|
|
|
Post by Wormopolis on Jun 11, 2010 12:52:58 GMT -8
There is no real code. I didnt really write a code to do anything here. this was all just little pieces of a ficticious code...
this might be easier if you actually had some sort of code you are trying to write.
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 11, 2010 18:05:03 GMT -8
well i am trying to aply this to my affiliate table i just am not smart enough to understand this stuff yet
|
|
|
Post by Wormopolis on Jun 11, 2010 19:36:53 GMT -8
so what you need to do, is draw similarities between our fictitious code, and you side tables code.
what is the HTML part?
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 12, 2010 5:40:46 GMT -8
here
<table width="92%" align="center"> <tr><td width="200px" valign="top" style="padding-top: 40px;">
<table width="200px" cellpadding="4px" class="bordercolor" cellspacing="1"> <tr><td align="center" class="titlebg" valign="top" > Affiliates </td></tr> <tr><td class="windowbg">
<center>
<img src="put url of your mini banner here" width="88" height="31" alt="" title="Copy Affiliate Code" onclick='affcode("put url of your mini banner here");'; style="cursor:pointer;"/><br>
click banner to get affiliate code
<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="up" scrollamount="3">
<!-- ===== affiliate codes start here put a <br> after each two affiliates ===== -->
<center> <a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a>
<a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a><br>
</marquee> </center> </td></tr></table> </td><td width="100%">
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 12, 2010 5:46:39 GMT -8
is this rite?
<script> var nwTbl="<table width="92%" align="center"> <tr><td width="200px" valign="top" style="padding-top: 40px;">
<table width="200px" cellpadding="4px" class="bordercolor" cellspacing="1"> <tr><td align="center" class="titlebg" valign="top" > Affiliates </td></tr> <tr><td class="windowbg">
<center>
<img src="put url of your mini banner here" width="88" height="31" alt="" title="Copy Affiliate Code" onclick='affcode("put url of your mini banner here");'; style="cursor:pointer;"/><br>
click banner to get affiliate code
<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="up" scrollamount="3">
<!-- ===== affiliate codes start here put a <br> after each two affiliates ===== -->
<center> <a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a>
<a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a><br>
</marquee> </center> </td></tr></table> </td><td width="100%">"; if (document.getElementById('linktable')) document.getElementById('linktable').innerHTML=nwtbl;
</script>
|
|
|
Post by Wormopolis on Jun 12, 2010 6:53:15 GMT -8
yes except you would have a problem with quotes. either you have to escape all of the ones inside or use single quotes to bookend the variable.
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 12, 2010 14:27:23 GMT -8
like this
<script> var nwTbl='<table width="92%" align="center"> <tr><td width="200px" valign="top" style="padding-top: 40px;">
<table width="200px" cellpadding="4px" class="bordercolor" cellspacing="1"> <tr><td align="center" class="titlebg" valign="top" > Affiliates </td></tr> <tr><td class="windowbg">
<center>
<img src="put url of your mini banner here" width="88" height="31" alt="" title="Copy Affiliate Code" onclick='affcode("put url of your mini banner here");'; style="cursor:pointer;"/><br>
click banner to get affiliate code
<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="up" scrollamount="3">
<!-- ===== affiliate codes start here put a <br> after each two affiliates ===== -->
<center> <a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a>
<a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a><br>
</marquee> </center> </td></tr></table> </td><td width="100%">'; if (document.getElementById('linktable')) document.getElementById('linktable').innerHTML=nwtbl;
</script>
|
|
|
Post by Wormopolis on Jun 12, 2010 15:39:17 GMT -8
much better, and now remove the line breaks that will cause a syntax error inside the variable. it makes it harder to read of course, but the compiler requires it.
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 12, 2010 16:31:26 GMT -8
wormo do you use a program to help you write codes?
<script> var nwTbl='<table width="92%" align="center"> <tr><td width="200px" valign="top" style="padding-top: 40px;">
<table width="200px" cellpadding="4px" class="bordercolor" cellspacing="1"> <tr><td align="center" class="titlebg" valign="top" > Affiliates </td></tr> <tr><td class="windowbg">
<center>
<img src="put url of your mini banner here" width="88" height="31" alt="" title="Copy Affiliate Code" onclick='affcode("put url of your mini banner here");'; style="cursor:pointer;"/>
click banner to get affiliate code
<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="up" scrollamount="3">
<center> <a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a>
<a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a> </marquee> </center> </td></tr></table> </td><td width="100%">'; if (document.getElementById('linktable')) document.getElementById('linktable').innerHTML=nwtbl;
</script>
|
|
|
Post by Wormopolis on Jun 12, 2010 16:42:55 GMT -8
not really. I even edit all my codes directly in the PB editor (though I DO use subdevo's jump to code code he wrote because it is great.. though I did some edits to it). typically its all trial and error for me when I write stuff. I tend to have both FF and IE open to the same place so I can see the results in both browsers, and a third window open in Firefox for the editing. when I make changes, I hit backspace and refresh because its faster.
<script> var nwTbl='<table width="92%" align="center"><tr><td width="200px" valign="top" style="padding-top: 40px;"><table width="200px" cellpadding="4px" class="bordercolor" cellspacing="1"><tr><td align="center" class="titlebg" valign="top" >Affiliates</td></tr><tr><td class="windowbg"><center><img src="put url of your mini banner here" width="88" height="31" alt="" title="Copy Affiliate Code" onclick='affcode("put url of your mini banner here");'; style="cursor:pointer;"/>click banner to get affiliate code<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="up" scrollamount="3"><center><a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a><a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a></marquee></center></td></tr></table></td><td width="100%">'; if (document.getElementById('linktable')) document.getElementById('linktable').innerHTML= nwtbl; </script>
or if it makes it easier to edit:
<script> var nwTbl='<table width="92%" align="center">'; nwTbl+='<tr><td width="200px" valign="top" style="padding-top: 40px;">'; nwTbl+='<table width="200px" cellpadding="4px" class="bordercolor" cellspacing="1">'; nwTbl+='<tr><td align="center" class="titlebg" valign="top" > Affiliates</td></tr>'; nwTbl+='<tr><td class="windowbg"><center><img src="put url of your mini banner here" width="88" height="31" alt="" title="Copy Affiliate Code" onclick='affcode("put url of your mini banner here");'; style="cursor:pointer;"/>'; nwTbl+='click banner to get affiliate code'; nwTbl+='<marquee onmouseover="this.stop()" onmouseout="this.start()" direction="up" scrollamount="3">'; nwTbl+='<center><a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a>'; nwTbl+='<a href="website url" target="_blank"><img src="mini banner" height="31" width="88" border="0" alt="name" /></a>'; nwTbl+='</marquee></center></td></tr></table>'; nwTbl+='</td><td width="100%">'; if (document.getElementById('linktable')) document.getElementById('linktable').innerHTML=nwtbl;
</script>
though you might want to check that HTML again, because you have 2 opening center tags, and only 1 closing one. And you open a new td tag at the very end for some reason, but never close the very first tr or table tags you opened.
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jun 12, 2010 17:09:06 GMT -8
i am going to summer camp so i can't spend no more time on this untill next week. Talk to ya then
|
|
|
Post by Wormopolis on Jun 12, 2010 23:46:35 GMT -8
wow... I didnt know kids still did that.
have fun?
|
|