473,395 Members | 1,473 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,395 software developers and data experts.

register onclick problem

25
I ran into a strange problem:

I'm adding and removing rows dynamicly,
each row has it's id and remove button

when I removing a row i go on all the next rows and update their ID
I also need to update the delete row button.

the problem is that the button has onclick="deleteRow(rowId)"

and when I remove a row and update all the next elements

all of them are calling the deleteRow with the same ID (the id of last one)

Expand|Select|Wrap|Line Numbers
  1. i = currentID;
  2. while(i < ElementsCounter){
  3.     newID = i - 1;
  4.     $("delete"+i).id = "delete"+newID;
  5.     $("delete"+newID).onclick = function(){ deleteRow(newID); };
  6. }
  7.  
any idea will help
Nov 24 '07 #1
11 1556
obarash
25
setting onclick of one element happans to effect other elements onclick

I'm adding and removing rows dynamicly,
each row has it's id and remove button.

when I removing a row i update all the next rows IDs
and the onclick functino to call the deleteRow(rowID) with the new ID.

All next elements onclick function
is calling the deleteRow function with the same ID (the id of last iteration)

for example:
all of the button call deleteRow(2)


[PHP]i = currentID;
while(i < ElementsCounter){
newID = i - 1;
document.getElementById("delete"+i).id = "delete"+newID;
document.getElementById("delete"+newID).onclick = function(){ deleteRow(newID); };
}[/PHP]

Thanks from advance
Nov 25 '07 #2
acoder
16,027 Expert Mod 8TB
Merged duplicate threads.

How about passing "this" to the delete function instead?
Nov 26 '07 #3
obarash
25
Merged duplicate threads.

How about passing "this" to the delete function instead?

if I pass the obj itself how can i get the row ID?

there is another way to add an onlick event?
Nov 26 '07 #4
I ran into a strange problem:

I'm adding and removing rows dynamicly,
each row has it's id and remove button

when I removing a row i go on all the next rows and update their ID
I also need to update the delete row button.

the problem is that the button has onclick="deleteRow(rowId)"

and when I remove a row and update all the next elements

all of them are calling the deleteRow with the same ID (the id of last one)

Expand|Select|Wrap|Line Numbers
  1. i = currentID;
  2. while(i < ElementsCounter){
  3.     newID = i - 1;
  4.     $("delete"+i).id = "delete"+newID;
  5.     $("delete"+newID).onclick = function(){ deleteRow(newID); };
  6. }
  7.  
any idea will help
what is "$"
and i is not getting decrementted
Nov 27 '07 #5
acoder
16,027 Expert Mod 8TB
if I pass the obj itself how can i get the row ID?

there is another way to add an onlick event?
If you're deleting a row, why do you need the row ID? However, if you really need it, use the rowIndex property.
Nov 27 '07 #6
obarash
25
If you're deleting a row, why do you need the row ID? However, if you really need it, use the rowIndex property.
Thanks I'll see if I can use it
Nov 27 '07 #7
obarash
25
what is "$"
and i is not getting decrementted
$ is prototype refernce.
the implementation is very easy:

function $(element){
return document.getElementById(element);
}

in the prototype libary there a simple validition if it is an obj
Nov 27 '07 #8
obarash
25
If you're deleting a row, why do you need the row ID? However, if you really need it, use the rowIndex property.
I can't use it my code is like this
<tr>
<td>
<table>
<tr>
<td>
<td>
<td>button</td>
<tr>
</table>
<td>
<tr>

I need it to stay as is my problem is relly in the 'this'
in the loop that i described before if i write this it is not a refernce to the button itself.
how can i pass this?
Nov 27 '07 #9
acoder
16,027 Expert Mod 8TB
Can you post the rest of the code (if it's not too much) or a link?
Nov 27 '07 #10
obarash
25
Can you post the rest of the code (if it's not too much) or a link?
i solved my problem!!

I've set the <td> that contatins the button only the row id and just call deleteRow()

in the deleteRow():
var obj = event.srcElement;

and then I use obj.parentNode.id

and in the loop i just update the <td> id.
Nov 27 '07 #11
acoder
16,027 Expert Mod 8TB
i solved my problem!!

...
in the deleteRow():
var obj = event.srcElement;
Glad you managed to solve it. Just a note though: srcElement is IE-only. You need to use target for standards-compliant browsers. See, for example, this link.
Nov 28 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Robert M. | last post by:
Information: Server A: SQL Server 2000 Enterprise Edition. OS is Windows 2003 Server Enterprise Edition. SQL Service pack is 3a. Member of domain ABCDomain. Server A is going to function as a...
8
by: Shock | last post by:
Hello everyone, I am having a problem with the program below. I have isolated the problem to the onclick event that is located throughout arrQuestions. The onclick event refers to a function...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
33
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a...
5
by: prouleau001 | last post by:
Hi all! Since that the decorator syntax is upon us, I think it would be good if atexit.register() was returning the function passed as argument. This simple change to the library would solve a...
3
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick...
3
by: shapper | last post by:
Hello, I want to register the JQuery Javascript file at runtime in my Page's VB code. Do I need or should I to do this using ScriptManger? If not, how can I do it? Thanks, Miguel
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.