473,466 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple onloads, variable timing, filling form or tags during onload

2 New Member
I'm new to forum and am learning javascript. I appreciate your help and patience in advance. I run an image gallery website that uses an onload event called FitPic() to scale image and window sizes to fit the users monitor resolution. FitPic() creates certain variables that would be useful for other calculations, such as reporting the % of image scaling. However, since onload events occur last during rendering, the variables are not available when I'd like to use them.

I think the answer lies with using a second onload event. This would make FitPic() variables accessible (I think). However, the second onload needs to fill a textbox or other html tag on the page. That's where I'm struggling.

My current code is structured like this. It obviously fails because I'm trying to render the ScaleAmt() function using variables that aren't accessible until the onload FitPic() fires.

Expand|Select|Wrap|Line Numbers
  1. function FitPic() { 
  2. ImgWidth = [new image width calculated through this function]
  3. OriginalImgWidth = [original image width]
  4. }
  5.  
  6. function ScaleAmt() {
  7. o = OriginalImgWidth;
  8. n = ImgWidth; 
  9. r = parseInt((n/o) * 100);
  10. return r;
  11.  
  12. <body onload="FitPic();>
  13.  
  14. then later....
  15. document.write( "<p>Image is " + ScaleAmt() + "% of original size</p>"); 
  16.  
  17. </body>
  18.  
  19.  
Any ideas how I can structure these functions and events. Basically, I need to use the onload FitPic variables to do some calculations, like ScaleAmt, and render the result somewhere on the page.

Thanks for any and all help.
Aug 3 '07 #1
3 2046
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Instead of using document.write, have a div on your page with an id, e.g
[HTML]<div id="imgScaleMsg"></div>[/HTML] then update it in FitPic():
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("imgScaleMsg").innerHTML = "<p>Image is " + ScaleAmt() + "% of original size</p>";
Aug 3 '07 #2
zepdad
2 New Member
Thanks. I knew there was a simple solution. Worked like a charm.
Aug 3 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Thanks. I knew there was a simple solution. Worked like a charm.
Glad you got it working. Post again if you have any more problems.
Aug 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
4
by: Howard Jess | last post by:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865), my form disappears from the HTML markup (below). To summarize: 1) In a <script> block in the <head> I create a form...
2
by: George | last post by:
How can I do the following in python: given two strings: form=""" <html> <head> <title> My Sample Web Page </title> </head> <body bgcolor="white"> <p> What are the weekdays? <ol>
19
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
2
by: John J. Lee | last post by:
I was cheered to see that this guy claims to have solved the problem with onload only firing very late: http://dean.edwards.name/weblog/2005/09/busted/ However, "ash" comments on that...
3
by: stephenedavis | last post by:
I keep getting the error message "Invalid postback or callback argument" on my asp.net 2.0 pages in Internet Explorer. These pages are simple, and just to make sure there is nothing wrong with the...
5
by: steve.chambers | last post by:
I'm sure this q must have been asked before but I'm really struggling to find the answer anywhere so have finally given up and will consult the usenet community - hopefully there's someone out...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.