[Javascript] onclick and functions

tedd tedd at sperling.com
Sat Aug 12 09:24:31 CDT 2006


Hi gang:

Two questions (please be kind):

1. Why do the alerts show at start-up?

2. Why does the onclick not work (i.e., no alerts)?

I spent a lot of time trying to find a reference, but couldn't find 
anything regarding this. Everything I read suggested that this should 
work.

What I simply want to do is to call a function (while passing a 
variable) by clicking a div.

I must be doing something very simple, very wrong -- what is it?

Thanks.

tedd

----

html --

<div id="test1">
This is test 1
</div>

<div id="test2">
This is test 2
</div>


js ---

<script type="text/javascript">

var a = 	document.getElementById("test1");
var b = 	document.getElementById("test2");

function test1(c)
	{
	var d = c + 1;
	alert(d);
	}

function test2()
	{
	var d = 1;
	alert(d);
	}

a.onclick = test1(1);
b.onclick = test2();

</script>
-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the Javascript mailing list