special "for" not working and passing arguments to events

K

knocte

Hello group.

In the following testcase I attach to the final of the message, I have
two questions:

1) According to comment # 1, how can I pass an argument to the
function that way?

2) According to comment # 2, why this special structure for the "for"
statement is not working?

Testcase:

<html><head><title>Testcase</title>
<script type="text/javascript" language="JavaScript">
<!--
function Alert(number) {
window.alert("A element clicked!(number:" + number + ")");

return false;
}

function ApplyAlerts() {
var oAElement = window.document.getElementById('alert1');
oAElement.onclick = Alert; //how can I pass an argument? [comment
#1]

var aElements = window.document.getElementsByTagName('a');

for (var i = aElts.length; i--; ) { var oElement = aElts; //this
works
//for (oElement in aElts){ //Why this doesnt work? [comment #2]

if (oElement.id)
if (oElement.id == 'alert2')
oElement.onclick = Alert;
}
}

window.onload = ApplyAlerts;
//-->
</script></head>
<body id="body">
<div id="test">
<a id="alert1" name="alert1" href="http://www.google.com"
target="_blank">Link1</a><br />
<a id="alert2" name="alert2" href="http://www.google.com"
target="_blank">Link2</a>
</div>
</body></html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top