Re: feeling stupid....

Peter-Paul Koch <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
>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

<*> 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.