473,790 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ 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 2081
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
8133
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 title. I am trying to change the title of the IFrame window to be that of the contained window title. If I uncomment the alert statement below - the title change works. Comment out the alert - and - no title change.
4
2544
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 element (part of object/feature/bug detection). 2) There's a <form> element defined in the <body>, with the id 'theForm'. 3) The onload function tries to access that form, and also counts the total number of forms in the document. It fails to...
2
1870
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
3480
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
2428
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 page:
3
1435
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 HTML, I created an empty page with just the following in it: <asp:Button runat="server" ID="Submit1" Text="Submit"></asp:Button> When I navigate to this page and wait for the progress bar to show it is complete 100% and then quickly click on...
5
6161
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 there who's seen it all before and can help me out! I have a webpage which needs to make some function calls after the page has loaded - won't go into details surfice to say here is a code fragment: function addLoadEvent(func) { var oldonload =...
16
8398
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 have 3 methods A, B and C. All of them shall be run threaded (I/O tasks) and one after another. I can create a thread and schedule one method just like:
3
3928
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 messing up. Problems:
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9987
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9023
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
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 we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.