473,388 Members | 1,234 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.

How to use windows onload fuction twice in a same page

5
I have a java script which I used for passing check boxes values to text box. But it does not work if i use it twice in a same page. How can I use it many times in a same page?


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <script type="text/javascript">
  4.  
  5.  
  6.  
  7.  
  8. window.onload=function(){
  9.     var textbox = document.getElementsByName("textname")[0];
  10.     var checkboxes = document.getElementsByName("checkboxname");
  11.     for (var i = 0; i < checkboxes.length; i++) {
  12.         var checkbox = checkboxes[i];
  13.         checkbox.onclick = (function(chk){
  14.             return function() {
  15.                 var value = "";
  16.                 for (var j = 0; j < checkboxes.length; j++) {
  17.                     if (checkboxes[j].checked) {
  18.                         if (value === "") {
  19.                             value += checkboxes[j].value;
  20.                         } else {
  21.                             value += "," + checkboxes[j].value;
  22.                         }
  23.                     }
  24.                 }
  25.                 textbox.value = value;
  26.             }
  27.         })(checkbox);
  28.     }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. </script>
  38.  
  39.  
Sep 27 '13 #1

✓ answered by Dormilich

just replace window.onload=function(){} by window.addEventListener("load", function(evt) {})

4 10182
Dormilich
8,658 Expert Mod 8TB
it’s simple, you can’t.

you have to use Event Listeners to attach more than one handler to a single event:
Expand|Select|Wrap|Line Numbers
  1. window.addEventListener("load", function1);
  2. window.addEventListener("load", function2);
  3. window.addEventListener("load", function(evt) { /* ... */ });
Sep 27 '13 #2
bhitra
5
hey can you help me by writing an event listener because i am beginner. I copied the java script code from somewhere, i don't know where i add even listener code.
Sep 27 '13 #3
Dormilich
8,658 Expert Mod 8TB
just replace window.onload=function(){} by window.addEventListener("load", function(evt) {})
Sep 27 '13 #4
bhitra
5
a million dollar thanks to you. It finally worked.
Sep 28 '13 #5

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

Similar topics

3
by: Archie Campbell | last post by:
Most people cancel the "allow anonymous user" and IIS will automatically popup the user login dialog. Not me. I want anonymous users to be able to do somethings. Then, if they want to do more,...
2
by: Andy | last post by:
Is it possible to execute a C# Windows app from an ASPX (C#) web application. My app runs over the Intranet and on one page I want to run a C# program which does some things I can't do from the...
4
by: Joe Kehnast | last post by:
I'm running a system on W2K web server with a Professional XP client. I'm opening a window from an asp page using showModalDialog. In the window I open I'm calling the onLoad event from the body...
0
by: Netsharp Ninja | last post by:
Hello All, I am trying to develop a windows control to use in ASP.NET page. I have seen the samples given by .NET Framework and trying to repeat the same with my own pages. I succeded half way...
2
by: Mike D | last post by:
I have a windows control in an aspx page. It receives data from some serial hardware on the client. How do I get this data to an aspx page so that I can post it to the server? I will need to...
2
by: Shahzad Godil | last post by:
I have successfully placed a seperate .Net windows control on my aspx page as well as one ActiveX Control (Visio control) on my aspx. But my orignal design is that Visio activex will be placed in...
1
by: Husam | last post by:
Hi EveryBody: How can I convert my Windows application Form to Web Page by Importing some class from ASP.Net ? In other word I want to add the following editor which is htmlArea v2.03 code...
0
prabunewindia
by: prabunewindia | last post by:
hi friends, could anybody say how to call a windoms form from a web page and call a web page from a windows form. i did a web and window applications separately. i wanna join both as one how can...
3
by: archana | last post by:
Hi all, I want to open one page without navigating user to another page. What i am having is having aspx page having calender control.this aspx page i am showing to user when user want to set...
2
by: carlac4509 | last post by:
How do I get my PC to let me select my user name and get to the windows icon page? I'm not really a computer person, so please explain everything simply and thoroughly when you respond. Thank you...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.