472,981 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 1725
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.