Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with javascript, I think 2

Status
Not open for further replies.

piratefan

Programmer
Jul 20, 2003
195
US
<SCRIPT LANGUAGE=&quot;Javascript&quot;><!--
function banner() {} ; b = new banner() ; n = 0;

b[n++]= &quot;<A HREF=' target='_PARENT'><IMG SRC=' BORDER='2'></A>&quot;

b[n++]= &quot;<A HREF=' target='_PARENT'><IMG SRC=' BORDER='2'></A>&quot;

i=Math.floor(Math.random() * n) ;
document.write( b )
//--></SCRIPT>

I am trying to use the above code in a table cell. I recently switched my message board. This code worked fine on the old message board. For some reason, the banner is not showing up and I am getting a &quot;done, but with errors&quot; when the page loads. I feel pretty certain all my tags are closed correctly.
Those capital letters shouldn't matter should they? I mean in the anchor element.
Thanks.
 
I don't know how I cut and paste and had that mistake. The code did look like this :

document.write( b ) (without the ;). I changed to :
document.write( b );
I don't get the done with errors message but my banner is still not showing up.

Would that normally mean a tag issue? Like I said, it worked fine before but I did have to monkey with the structure of the tables.
 
You still need to put b, whether or not you have a ; character at the end of the line or not... b is an object... b are the individual strings you want to write out.

The code I gave above does work - honest ;o)

Dan
 
My mistake again. Old age. I have what you are suggesting already.
document.write( b ) ; This has been in my code all along, without the semicolon. By the way, I did get a few pages without the error but it still occurs occasionally.
 
Aaargh... Bloomin code isn't showing up... Let's try that post again (third time lucky!)

Code:
You still need to put b[i], whether or not you have a ; character at the end of the line or not... b is an object... b[i] are the individual strings you want to write out.

Dan
 
BillyRayPreachersSon,

When posting code to Tek-tips enclose your code in
Code:
.

-Ron

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
Let's try that again

&#91;code&#93;&#91;/code&#93;

-Ron

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
Ron,

I know - I suggested that myself... And i always do enclose my code in code tags... But I didn't realise that
Code:
[i]
by itself in a sentence turned italics on and off...

Thanks for the reminder ;o)

Dan
 
Oops, sorry Dan. That salutation was supposed to be to piratefan, not you. [wink]

-Ron

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
My apologies for all the above. Something is happening to my code when I submit these replies. I have the exact code you are telling me to use. I have :

Code:
document.write( b[i]);

I have had it all along. Guess I need to preview these posts first. When I cut and paste, something is making it change. And I am using the code brackets but when I preview they are gone. Am I supposed to put code in red?

Thanks.
 
No, the red is something I added for clarification. The code brackets are supposed to disappear. Look at your most recent post, the code is shown in a serif font instead of a sans serif font. It is also spaced differently.

This is to help differentiate between code and regular text in a post. It also shows all characters literally instead of trying to process TGML (techumseh group markup language).

In TGML,
Code:
[i]
turns text into italics. That is why you're previous posts appeared the way they did.

Click the Process TGML link just above the &quot;Submit Post&quot; button on this page for more information about TGML.

-Ron

-We all play from the same deck of cards, it's how we play the hand we are dealt which makes us who we are.
 
Code:
<table>
  <tr valign=&quot;top&quot;>
     <td width=&quot;120&quot;> <br><br><br>
         <table valign=&quot;top&quot;>
             <tr>
                <td>
                    <a href=&quot;[URL unfurl="true"]http://www.sponsor1.com&quot;[/URL] target=&quot;_PARENT&quot;><img src=&quot;[URL unfurl="true"]http://www.mydomain.com/phpBB2/sponsor1.gif&quot;[/URL] width=&quot;120&quot; height=&quot;60&quot;></a>
                </td>
             </tr>
             <tr>
                <td>
                    <a href=&quot;[URL unfurl="true"]http://www.sponsor2.com&quot;[/URL] target=&quot;_PARENT&quot;><img src=&quot;[URL unfurl="true"]http://www.mydomain.com/phpBB2/sponsor2.gif&quot;[/URL] width=&quot;120&quot; height=&quot;120&quot;></a>
                </td>
             </tr>
             <tr>
                <td>
                    <a href=&quot;[URL unfurl="true"]http://www.sponsor3.com&quot;[/URL] target=&quot;_PARENT&quot;><img src=&quot;[URL unfurl="true"]http://www.mydomain.com/phpBB2/sponsor3.gif&quot;[/URL] width=&quot;120&quot; height=&quot;60&quot;></a>
                </td>
             </tr>
        </table>
     </td>
     <td width=&quot;100%&quot;>
        <table width=&quot;100%&quot;>
          <tr>
            <td align=&quot;center&quot;>

                 <SCRIPT LANGUAGE=&quot;Javascript&quot;><!--
function banner() {} ; b = new banner() ; n = 0;

b[n++]= &quot;<A HREF='[URL unfurl="true"]http://www.sponsor4.com'[/URL] target='_PARENT'><IMG SRC='[URL unfurl="true"]http://www.mydomain.com/phpBB2/sponsor4.gif'[/URL] BORDER='2'></A>&quot;


b[n++]= &quot;<A HREF='[URL unfurl="true"]http://www.sponsor5.com'[/URL] target='_PARENT'><IMG SRC='[URL unfurl="true"]http://www.mydomain.com/phpBB2/sponsor5.gif'[/URL] BORDER='2'></A>&quot;





i=Math.floor(Math.random() * n) ; 
document.write( b[i] ) ;
//--></SCRIPT>v
           </td>
          </tr>    
       </table>  
          
          
        <table width=&quot;100%&quot;>
          <tr>
             <td align=&quot;center&quot;>
                       <a href=&quot;[URL unfurl="true"]http://www.sponsor1.com&quot;[/URL] target=&quot;_PARENT&quot;><font size=&quot;1&quot; color=&quot;blue&quot;>Sponsor1</font></a>
             </td>
             <td align=&quot;center&quot;>
                       <a href=&quot;[URL unfurl="true"]http://www.sponsor2.com&quot;[/URL] target=_PARENT&quot;><font size=&quot;1&quot; color=&quot;blue&quot;>Sponsor2</font></a>   
             </td>
             <td align=&quot;center&quot;>
                       <a href=&quot;[URL unfurl="true"]http://www.sponsor3.com&quot;[/URL] target=&quot;_PARENT&quot;><font size=&quot;1&quot; color=&quot;blue&quot;>Sponsor3</font></a>
             </td>
          </tr>
          <tr>
             <td align=&quot;center&quot;>
                        <a href=&quot;[URL unfurl="true"]http://www.sponsor4.com&quot;[/URL] target=&quot;_PARENT&quot;><font size=&quot;1&quot; color=&quot;blue&quot;>Sponsor4</font></a>
             </td>
             <td align=&quot;center&quot;>
                        <a href=&quot;[URL unfurl="true"]http://www.sponsor5.com&quot;[/URL] target=&quot;_PARENT&quot;><font size=&quot;1&quot; color=&quot;blue&quot;>Sponsor5</font></a>
             </td>
             <td align=&quot;center&quot;>
                        <a href=&quot;[URL unfurl="true"]http://www.sponsor6.com&quot;[/URL] target=&quot;_PARENT&quot;><font size=&quot;1&quot; color=&quot;blue&quot;>Sponsor6</font></a>
             </td>
          </tr>
       </table>

       <table width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;10&quot; border=&quot;0&quot; align=&quot;center&quot;> 
	<tr> 
		<td class=&quot;bodyline&quot;><table width=&quot;100%&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;>
			<tr> 
				<td><a href=&quot;[URL unfurl="true"]http://www.mydomain.com&quot;><img[/URL] src=&quot;templates/subSilver/images/wwgif.gif&quot; border=&quot;0&quot; alt=&quot;{L_INDEX}&quot; vspace=&quot;1&quot; /></a></td>
				<td align=&quot;center&quot; width=&quot;100%&quot; valign=&quot;middle&quot;><span class=&quot;maintitle&quot;>{SITENAME}</span><br /><span class=&quot;gen&quot;>{SITE_DESCRIPTION}<br />  </span> 
				<table cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; border=&quot;0&quot;>
					<tr> 
						<td align=&quot;center&quot; valign=&quot;top&quot; nowrap=&quot;nowrap&quot;><span class=&quot;mainmenu&quot;> <a href=&quot;{U_FAQ}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_faq.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_FAQ}&quot; hspace=&quot;3&quot; />{L_FAQ}</a></span><span class=&quot;mainmenu&quot;>   <a href=&quot;{U_SEARCH}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_search.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_SEARCH}&quot; hspace=&quot;3&quot; />{L_SEARCH}</a>   <a href=&quot;{U_MEMBERLIST}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_members.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_MEMBERLIST}&quot; hspace=&quot;3&quot; />{L_MEMBERLIST}</a>   <a href=&quot;{U_GROUP_CP}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_groups.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_USERGROUPS}&quot; hspace=&quot;3&quot; />{L_USERGROUPS}</a>  
						<!-- BEGIN switch_user_logged_out -->
						 <a href=&quot;{U_REGISTER}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_register.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_REGISTER}&quot; hspace=&quot;3&quot; />{L_REGISTER}</a></span> 
						<!-- END switch_user_logged_out -->
						</td>
					</tr>
					<tr>
						<td height=&quot;25&quot; align=&quot;center&quot; valign=&quot;top&quot; nowrap=&quot;nowrap&quot;><span class=&quot;mainmenu&quot;> <a href=&quot;{U_PROFILE}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_profile.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_PROFILE}&quot; hspace=&quot;3&quot; />{L_PROFILE}</a>   <a href=&quot;{U_PRIVATEMSGS}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_message.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{PRIVATE_MESSAGE_INFO}&quot; hspace=&quot;3&quot; />{PRIVATE_MESSAGE_INFO}</a>   <a href=&quot;{U_LOGIN_LOGOUT}&quot; class=&quot;mainmenu&quot;><img src=&quot;templates/subSilver/images/icon_mini_login.gif&quot; width=&quot;12&quot; height=&quot;13&quot; border=&quot;0&quot; alt=&quot;{L_LOGIN_LOGOUT}&quot; hspace=&quot;3&quot; />{L_LOGIN_LOGOUT}</a> </span></td>
					</tr>
				</table></td>
			</tr>
		</table>



      </td>

  </tr>


</table>

I hope I can do this okay. I tried abbreviating the code some. Shortened the anchor tags as best I could for simplicty. The last table I apologize for because it is code that was already in place with my message board and I am afraid if I try to abbreviate that, I may look dumber than I am.

I restate that I hope I am not doing anything wrong by posting the code. As I said, the table cell(banner) with the javascript does not show and I get the error message down in the lower left corner of the browser &quot;done, with page errors&quot;.

I am also reluctant to post this because I am very new with this html or xhtml stuff. I want to learn it in the worst way. Something tells me it's not very good the way I have it set up. I am trying to put 120x60 banners down the side of my page. With the rest of the tables making up the remainder of the page.

Thank you very much.
 
hey pirate, just in case you didnt realise... there is a forum dedicated to javascript..

[xmastree][reindeer][santa]

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
I'm not sure my problem is JavaScript or html. Does it hurt to try posting the javascript part in that forum? Some forums don't like cross posting. Don't want to step on any toes.
 
no worries, i post in both if im unsure [2thumbsup]

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
piratefan,

Does putting a semicolon (';') character at the end of lines 30 and 33 (the two javascript lines that begin with 'b[n++]') make any difference?

What browser(s) are you getting the error message in? I don't find anything wrong in IE 6 or NN 7...

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top