LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2008, 02:41 PM   #1
plk
Member
 
Registered: May 2007
Location: Krakow, Poland
Distribution: Dell Inspiron 6400 - Intel Core 2 Duo - Ubuntu 8.04
Posts: 57

Rep: Reputation: 15
javascript onclick event nightmare ...


Hey all.

I'm having a problem with dynamically changing an onclick event. I know there are two solutions to this:

myVar.onclick = some_function;

or

myVar.onclick = function(){some_function();};

so.. why does that not work ?? :


[HTML]<html>
<head><title></title>
<script language="text/javascript" type="text/javascript" src="test.js">
</script>
</head>
<body>
<a href="#" id="id">Click me!</a>
</body>
</html>[/HTML]


with test.js:

Code:
	window.onLoad = initAll();

	// on load
	function initAll() {
		var the_change = document.getElementById('id');
		the_change.onclick=show_table;
	}

        function show_table() {
          // whatever
        }
note that the_change.onclick=function(){show_table();}; does not work neither ...

I'm lost .. honnestly.

thanks

plk
 
Old 10-13-2008, 12:19 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Quote:
so.. why does that not work ?? :
Couldn't you be more specific?

Quote:
Code:
        function show_table() {
          // whatever
        }
Let's assume, just for the sake of argument, that there is an error in this function. How do you think anyone will be able to help you debug "whatever"?
 
Old 10-13-2008, 02:49 AM   #3
plk
Member
 
Registered: May 2007
Location: Krakow, Poland
Distribution: Dell Inspiron 6400 - Intel Core 2 Duo - Ubuntu 8.04
Posts: 57

Original Poster
Rep: Reputation: 15
Ok sorry ...

Code:
function show_table() {
    alert('whatever');
}

plk
 
Old 10-13-2008, 03:13 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Code:
window.onLoad = initAll();
It has to be "onload", not "onLoad". Also, initAll will be called since you use the () after the function name, so the initAll function is called before the page is loaded.

Code:
window.onload = initAll;
should work.
 
Old 10-15-2008, 07:35 AM   #5
plk
Member
 
Registered: May 2007
Location: Krakow, Poland
Distribution: Dell Inspiron 6400 - Intel Core 2 Duo - Ubuntu 8.04
Posts: 57

Original Poster
Rep: Reputation: 15
And Yes it did !

I knew it was something like that.

Thank you very much ! :-)

plk
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
onClick to return to the same part of HTML document rblampain Programming 2 02-29-2008 04:47 AM
Javascript onclick doesn't work in IE mohtasham1983 Programming 9 02-01-2008 02:29 AM
Fire Event from other event in Visual C++ Express Edition chrisliando Programming 1 11-08-2007 05:12 PM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
handling windowclose event in javascript sajith Programming 1 03-25-2006 06:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration