www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Two Events

  1. #1
    Join Date
    Dec 2008
    Posts
    3

    resolved [RESOLVED] Two Events

    Need some help

    I have to events on my index page, but i cant get them both two work at the same time. I know that i cant use window.onload on both of them, that will only make one of the event too work. But i don't know how too modify the script to make the both work. I dont want the onclick in the html file, it has to be in the js file.

    popup.js

    Code:
    window.onload = initImages;
    
    function initImages() {
    	var allImages= document.getElementsByName("big");
    	
    	for (var i=0; i<allImages.length; i++) {
    		allImages[i].onclick = newWindow;
    	}
    }
    
    function newWindow() {
    	var imgName = "images/" + this.id + ".jpg";
    	var imgWindow = window.open(imgName, "imgWin", "width=430,height=340,scrollbars=no");
    }
    the url.js

    Code:
    window.onload = initExtlink;
    
    	function initExtlink() {
    	var allExternallinks= document.getElementsByName("external");
    	
    	for (var i=0; i<allExternallinks.length; i++) {
    		allExternallinks[i].onclick = newConfirm;
    	}
    }
    
    function newConfirm() {
      if(confirm('Du är på väg att lämna sidan. Klicka på OK för att fortsätta')) {
            return true;
        }
    	return false;
    }
    the html

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3c.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="url.js"></script>
    <script type="text/javascript" src="popup.js"></script>
    <title>Index</title>
    </head>
    
    <body>
    
    <a name="external" href="http://www.kissonline.com">Kissonline</a>
    
    <img name="big" class="bottom" src="images/diego_thumb.jpg" alt="Diego - Border Terrrier" id="diego" />
    
    </body>
    </html>

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    window.onload = function(){
    initExtlink();
    newConfirm();
    }

  3. #3
    Join Date
    Dec 2008
    Posts
    3

    Dosen't work

    It dosen't work.

    //vgarmy

  4. #4
    Join Date
    Oct 2008
    Posts
    349
    mrhoo must have misread the function names

    PHP Code:
    window.onload = function(){
    initExtlink();
    initImages();


  5. #5
    Join Date
    Dec 2005
    Posts
    155
    you can call two functions like what mrhoo has given, he got the function names wrong , i believe

    try this
    window.onload = function(){
    initImages();
    initExtlink();
    }

    Also comment window.onload = initImages; and window.onload = initExtlink; if you use the above. If it doesnot work and it is giving an error. Post the error.
    vanamali Juvvadi
    i have brains but sold it on ebay

  6. #6
    Join Date
    Dec 2008
    Posts
    3

    Smile In works

    Thanks guys, it works.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles