473,388 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

problems adding buttons to a page using a "for" loop

I'm learning javascript, and toward that end, I am recreating a page
"my way". The original page: http://stenbergcollege.com and the one
that I'm creating: http://www3.telus.net/neustaeter/Stenberg

When I added the buttons manually, everything was hunky-dory and it
looked pretty much exactly like the original page. When I changed the
script so that it uses the for loop to insert the top row of buttons,
space seems to get inserted between them, plus for some reason the
following <div> gets pushed way down, too.

Can anyone tell me what's going on?

Thanks,
Lance

Jul 23 '05 #1
8 1748
la*********@telus.net wrote:
When I added the buttons manually, everything was hunky-dory and it
looked pretty much exactly like the original page. When I changed the
script so that it uses the for loop to insert the top row of buttons,
space seems to get inserted between them, plus for some reason the
following <div> gets pushed way down, too.

Can anyone tell me what's going on?


In the #topnav css declaration, you define a width of 780px, which is fine,
but you also define a border of 1px, which makes the total width 782px
(780px + a border of 1px on the left and a border of 1px on the right).
Changing the width to 782px will fix this problem (or add a
white-space:nowrap property).

The div gets pushed down because you forgot to close the topnav div just
after the closing script tag.
JW

Jul 23 '05 #2
VK
for() loop by itself cannot change elements' positioning, you can take
my word for it.

I see the problem in your layout approach where you're using absolutely
positioned div's with absolutely positioned images in them and all this
within table cells. You told us that you want to do the page "your
way", so no advise about it (it's not a JavaScript problem anyway).

But from other side who wants to drink this cocktail as it is? ;-) It's
rather difficult even to see what part of your page this "gap"
apparteins to.
Could you please post a basic showcase?

Jul 23 '05 #3
"VK" <sc**********@yahoo.com> writes:
for() loop by itself cannot change elements' positioning, you can take
my word for it.


for(var i = 0; i < 100; document.getElementById('foo').style.left=i+'px',i ++);

Just proving a point :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #4
VK
> Just proving a point :)

Did you just smile?!

"for() loop by itself" means "by using this programming entity in your
code" (like "don't use addition operators anywhere or your page will
get corrupted")

Just proving a point :)

Jul 23 '05 #5
Doh! Thankyou so much. The missing </div> was the problem. I'm not
sure if the border contributed to the other problem (I added the border
because of the problem), but it went away after I fixed the missing
</div> as well, so I'm happy!

L

Jul 23 '05 #6
VK:
for() loop by itself cannot change elements' positioning, you can take
my word for it.
I noticed that the layout of my page would get slightly messed up based
strictly on exactly where I put my carriage returns when I placed the
buttons manually. The original (the one I'm reverse engineering) used
tables to position and wrapped each button image within an
anchor--which I've removed to just use the image with an "onclick"
event (I don't see very many recommendations on the internet about
this. Should I not do that and leave it as an Anchor-wrapped img?
IMO, anchors are for hypertext--but I'm a bit of a loose cannon).

Anyways: I figured out that I needed to put my carriage returns
*within* the tags and not between them. I supposed that, by using a
for loop to do what the original author had done manually might have
re-introduced that problem. But that wasn't the problem. (Perhaps
document.writeline() doesn't add a cr/lf at the end).
I see the problem in your layout approach where you're using absolutely
positioned div's with absolutely positioned images in them and all this
within table cells. You told us that you want to do the page "your
way", so no advise about it
I've removed the tables (they were from the original source that I was
changing). I'll post a link, if you're interested in where I'm at
now...
But from other side who wants to drink this cocktail as it is? ;-) It's
rather difficult even to see what part of your page this "gap"
apparteins to.
Could you please post a basic showcase?


I'll re-post the links. The original page: http://stenbergcollege.com

My problem page (cured by the addition of </div>.
Thanks Janwillem!): http://www3.telus.net/neustaeter/Stenberg

and where I'm at now (no more tables):
http://www3.telus.net/neustaeter/Ste...inprocess.html

Thanks,
L

Jul 23 '05 #7
VK
> My problem page (cured by the addition of </div>.
Thanks Janwillem!): http://www3.telus.net/neustaet*er/Stenberg
It's not cured, I still see the gap both in IE and FF (plus in IE the
last top menu item is shifted below other items).
The original page: http://stenbergcollege.com I think that this "learning" page was a bad choice on the first place
and it is the real source of your problem. It's a rather chaotic
agglomeration of what a person knows, barely knows and doesn't know at
all (reminds me my code sometimes though :-). If it's a side of your
friend, I'm really sorry, but it's true. But the graphics design is
excellent.
my page would get slightly messed up based
strictly on exactly where I put my carriage returns
when I placed the buttons manually.
No one browser reacts on the place and amount of spaces, carriage
returns and tabs in the source HTML code (unless you're using <pre> tag
or equivalent). If you can catch any of the Co on the act, it would be
a biggest discover of the WWW Era.
In your case I see just a mis-use of styles and tables (nothing to do
with JavaScript).
each button image within an anchor--which
I've removed to just use the image with an "onclick"
event (I don't see very many recommendations on
the internet about this.


Well, there were officially only two mouse events for <img>:
onmousedown and onmouseup. But it could be changed (I don't feel like
to see w3.org again right now, this morning is too beautiful for it).
The onmouseup could be a reliable alternative to avoid anchor wrappers.

<style>
image {cursor: pointer; cursor: hand}
</style>
would make your buttons to look like links

Jul 23 '05 #8
VK wrote:
Just proving a point :)
Did you just smile?!


Probably.
"for() loop by itself" means "by using this programming entity in your
code" (like "don't use addition operators anywhere or your page will
get corrupted")
He posted only a `for' statement (without a following block). Read again.
Just proving a point :)


As `for' is a control statement, your demand is ridiculous.
PointedEars, not smiling
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: siu02rk | last post by:
Hi All, Why doesn't the For Loop output the array "rabbit"? Here is the code : <html> <title> Hello World Script </title> <body> <?php $Name="Joe Blogg"; $a=a;
4
by: Deven Oza | last post by:
Hi, how can I write programm Using a for loop, that will print the first n integers. Thank you Dev
6
by: apking | last post by:
please write the programe in c language for this Accept 5 Employee details to find highest salary employe name using for loop and arrays Thanks in advance
0
by: HARISHAHI | last post by:
How to find first 3 and least rows of a table using row id( using for loop)?
1
by: Shailja | last post by:
Hi, How to increament a variable by 2 using For loop in VB 6.0. Kindly let me know if u know. Thanks
11
by: balaraja | last post by:
Hi how to print the diagonal elements of a two dimensional array using for loop Can any one help me...Plzzzzzzzz.. Thanks in advance Bala...
1
by: python101 | last post by:
I want to double a string by using 'for' loop in a special way for example: string1 = 'abc' #after doubled string1 = 'aabbcc' anyway, in python what does "+=" mean?
1
by: cokofreedom | last post by:
if __name__ == '__main__': print "Globals (For Loop):" try: for i in globals(): print "\t%s" % i except RuntimeError: print "Only some globals() printed\n" else: print "All globals()...
1
by: George21 | last post by:
Hi. I'm trying to delete selected item in listview. Can anyone help me? How can i delete selected item in Listview from menu using for loop?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.