Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-20-2003, 09:28 AM   #1 (permalink)
M3GAPL3X
Code Monkey
 
M3GAPL3X's Avatar
 
Join Date: Mar 2003
Location: California
Posts: 57
M3GAPL3X is on a distinguished road
Send a message via AIM to M3GAPL3X
JS Script question

Hi all,

I found a script that displays random images whenever a user visits my site. Here is what I have:

Code:
<script language="JavaScript">
<!--


function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" align=center border=1>')
}
random_imglink()
//-->
</script>
The problem with this is the:
document.write('<img src="'+myimages[ry]+'" align=center border=1>')
portion of the script. For some reason, it doesn't center. I know I am making a really easy mistake but for some reason, I don't know what it is. If I replace aligh=center with aligh=right, it seems to work.

Any help will be appreciated.
Thanks in advance.
__________________
--------------------------
M3GAPL3X@linuxmail.org
M3GAPL3X is offline   Reply With Quote
Old 04-20-2003, 11:53 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,705
redhead is on a distinguished road
hmm... why not surround it with a <center></center>?
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-20-2003, 04:37 PM   #3 (permalink)
agh
Registered User
 
Join Date: Apr 2003
Posts: 30
agh is on a distinguished road
The align attribute in the img tag isn't used to align the image. It aligns the text surrounding it.

You could try doing this instead:

Code:
<table>
    <tr>
        <td align="center">
            <!-- IMG TAG HERE -->
        </td>
    </tr>
</table>
Or you could try using CSS.

But putting align inside img won't work.
agh is offline   Reply With Quote
Old 04-20-2003, 04:40 PM   #4 (permalink)
agh
Registered User
 
Join Date: Apr 2003
Posts: 30
agh is on a distinguished road
Quote:
Originally posted by redhead
hmm... why not surround it with a <center></center>?
The <center> tag is deprecated... maybe it'll work, but I don't think you should use it.
agh is offline   Reply With Quote
Old 04-20-2003, 04:55 PM   #5 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
yer, align in the image won't work, shouldn't use "<center>" but you don't need to use a table

just do:


Code:
<div align="center">
   <img src="whatever" />
</div>
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 04-20-2003, 09:21 PM   #6 (permalink)
M3GAPL3X
Code Monkey
 
M3GAPL3X's Avatar
 
Join Date: Mar 2003
Location: California
Posts: 57
M3GAPL3X is on a distinguished road
Send a message via AIM to M3GAPL3X
Thumbs up

Thanks for the advice all. I used redheads method and it worked great!
__________________
--------------------------
M3GAPL3X@linuxmail.org
M3GAPL3X is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Something wrong with the view script redhead Lounge 1 10-11-2004 01:58 PM
running a script at designated time tzarin PHP 5 05-12-2004 07:11 PM
shell script for ftp Hrqls Linux / BSD / OS X 7 09-20-2002 03:14 AM
Question about a php prediction script(Great Site!) Geetazz PHP 15 06-12-2002 05:37 PM


All times are GMT -8. The time now is 02:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting