RE: feeling stupid....

"Seb Frost" <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
Thanks PPK,

el4.number = num;
el4.onclick = function() {deleteRow(this,this.number);return false;};

works a treat, and is much simpler than any workaround I would have
otherwise gone for!

cheers

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf
Of Peter-Paul Koch
Sent: 03 January 2006 12:41
To: [email protected]
Subject: Re: [wdf-dom] feeling stupid....



>num =1;
>el1.onclick = function() {deleteRow(this,num);return false;};
>num++;
>el2.onclick = function() {deleteRow(this,num);return false;};
>num++;
>el3.onclick = function() {deleteRow(this,num);return false;};
>
>
>The problem, as I'm sure you can guess, is that whichever element the user
>clicks on (thus invoking "deleteRow"), num is seen as being 3.

Scope. The three onclick functions share the scope of the main
function that defines them, and therefore have access to the variable
num. However, when the functions are invoked num is 3, since that is
the last value it has taken.

So either you hard-code the numbers, or store the number in the element
itself:

el.number = 1;
el1.onclick = function() {deleteRow(this,this.number);return false;};

>What I want is for it to be 1 on the first row, 2 on the second, and 3 on
>the third.

Or use the rowIndex property, which gives the number of the TR in its table.


-------------------------------------------------------------------
ppk, freelance web developer
http://www.quirksmode.org
------------------------------------------------------------------



Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html
Yahoo! Groups Links









Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.