473,414 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

special "for" not working and passing arguments to events

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[i]; //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>
Jul 23 '05 #1
1 1385
knocte wrote:
[...]
oAElement.onclick = Alert; //how can I pass an argument? [comment
#1]
Use a continuation:

oAElement.onclick = function() { Alert(42); };

[...] //for (oElement in aElts){ //Why this doesnt work? [comment #2]


You're not using IE5, are you? It has lousy Javascript support, including
not supporting the 'in' token. (It also barfs at // comments. Helpful.)

--
+- David Given --McQ-+
| dg@cowlark.com | Wholesale theft is the sincerest form of flattery.
| (dg@tao-group.com) |
+- www.cowlark.com --+

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Roy Smith | last post by:
I'm working on a prototype of a new application in Python. At some point, if this ever turns into a product, the powers that be will almost certainly demand that it be done in Perl. My job will...
23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
17
by: Istvan Albert | last post by:
Paul McGuire wrote: > Please reconsider the "def f() :" construct. Instead of > invoking a special punctuation character, it uses context and placement, > with familiar old 's, to infuse the...
13
by: Mike Austin | last post by:
Hi all. Just working on a small virtual machine, and thought about using vector iterators instead of pointer arithmetic. Question is, why does an iterator plus any number out of range not...
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
11
by: ajikoe | last post by:
Hello, I used Visual C# Standard Edition. I want to comment my program using xml commentary method, I don't know why if I use value and example tag, it is not working / showed in the html...
5
by: miktro | last post by:
I have an VB.Net desktop application where I am hosting a WebBrowser. I need to interact with the events in the browser. I encountered the normal problem of, after adding events the normal click...
2
by: rico.fabrini | last post by:
Hello Everyone, I've suddenly started running into the error "error executing child request for Page.aspx" when doing a Server.Transfer("Page.aspx"); That's on a Win2003 Server machine. ...
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.