<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>> Hi gang:<BR> <BR>> 1. Why do the alerts show at start-up?<BR>
That's because with: <FONT><FONT>a.<FONT>onclick</FONT></FONT></FONT> = test1(1)<BR>
You are assigning the complete body function to the <FONT>a.onclick (!treated as system "undefined" something)</FONT><BR>
it's the same as if you've writen:<BR>
test1(c) {<BR> var d = c + 1;<BR> alert(d);<BR>
equals anonymous <FONT>load-time function only that in this case; nowhere to assign c=1.</FONT><BR>
<BR>
> 2. Why does the onclick not work (i.e., no alerts)?<BR><BR>
Because it's not associated with the HTMLobject.event <BR> <BR>> What I simply want to do is to call a function (while passing a <BR>> variable) by clicking a div.<BR>At my knowledge, it can be done only through inline event function calls, that is:<BR>
<div id="test1" onclick="test(1,2,3)"> This is test 1 </div><BR>while the script could go like:<BR>
function test1(one,two,three) {<BR> var d = two + 1;<BR> alert(d);<BR> } <BR>
***some inline comments******<BR>
> html --<BR>> <BR>> <div id="test1"><BR>> This is test 1<BR>> </div><BR>> <BR>> <div id="test2"><BR>> This is test 2<BR>> </div><BR>> <BR>> <BR>> js ---<BR>> <BR>> <script type="text/javascript"><BR>> <BR>> var a = document.getElementById("test1");<BR>> var b = document.getElementById("test2");<BR>> <BR>> function test1(c)//In Netscape Browsers this will assign the onclick event to to the c variable;<BR>
// <FONT><FONT>ie will treat it as undeclared empty var </FONT></FONT><BR>
> {<BR>> var d = c + 1;//You are adding 1(number) to click event object; in ie you are adding NaN +1<BR>> alert(d); //will result click event 1 ; in ie NaN<BR>> }<BR>> <BR>> function test2()<BR>> {<BR>> var d = 1; //correctly assigned, value of d var is 1<BR>> alert(d);// will alert 1<BR>> }<BR>> <BR>
> <FONT>a.<FONT>onclick</FONT></FONT> = test1(1);//loadtime c: will alert (2) in 1 will be assigned to <FONT>c</FONT>; In ie same but immediately followed by error<BR>> <FONT><FONT>b.onclick</FONT></FONT> = test2();//correctly will alert (1); but ie has stopped load time exec after that error, no result will alert.<BR>> <BR>> </script><BR>
<BR>
<BR>
<BR>
Or something <BR>> -- <BR>> -------<BR>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR> Troy III<BR> progressive art enterprise<BR>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR><BR><br /><hr />Be one of the first to try Windows Live Mail. <a href='http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d' target='_new'>Windows Live Mail.</a></body>
</html>