www.webdeveloper.com
Results 1 to 2 of 2

Thread: need help in javascript code.

  1. #1
    Join Date
    Oct 2009
    Posts
    7

    need help in javascript code.

    I have a javascript code and want to extend this code now. how can I write a makeAMessenger function in global scope so that it triggers when user clicks document and alert

    Code:
    THIS. IS. SPART.
    currently I have following code.

    Code:
    function initiateMadness() {	
    	var sparta = {
            name : "Sparta"
        };
    
        function madness() {
        	alert("THIS. IS. " + this.name.toUpperCase() + ".");
    	}
    
    	document.onclick = makeAMessenger(madness, sparta);
    }
    
    initiateMadness();

  2. #2
    Join Date
    Nov 2007
    Posts
    413
    Try this:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Demo</title>
    <body>
    <div class="mainmenu">
    <button onclick="displayDate()" id="buttons" type="button">asdasd</button>
    </div>
    <div id="teams">
    <p id='test'>asdasd</p></div>
    </br> 
    
    
    <script type="text/javascript">
    window.onload = initiateMadness();
    
    function initiateMadness() {	
    	function location(name) {
    		this.name = name;
    	};
    
    	document.addEventListener('click', function(){madness()}, false);
    
    	function madness(){
    		var sparta = new Array();
    		sparta[0] = new location('sparta');
    		alert("THIS. IS. " + sparta[0].name.toUpperCase() + ".");
    	}
    
    }
    
    
    </script>
    </body>
    </html>

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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