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

set onClick property to a dynamically generated row

Hi all,

i ma adding a row dynamically and one of the cell contains an img icon...
to this img icon i want to set its onclick property.
i did it using the following:
imgElement.onClick = clickFunc();

but this calls the function when the cell is being appended to the dynamically added table row....
How can i make it working.

Here is the code

var seventhCell = newRow.insertCell(6);
var imgElement = document.createElement("img");
imgElement.src = "Delete.jpg";
imgElement.onClick = clickFunc(); //here is the problem.
seventhCell.appendChild(imgElement);


pls suggest something.
thnx in advance.
Mar 23 '07 #1
7 2389
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

Remove the parentheses. What you are currently doing is running the function and setting the result to the onclick. What you want is to set the actual function to the onclick by just using the name:
Expand|Select|Wrap|Line Numbers
  1. imgElement.onClick = clickFunc;
Mar 23 '07 #2
ssh
6
imgElement.onClick = clickFunc(); //here is the problem.

hi!

You can try the below code .. it should work ..

imgElement.onClick = function(){clickFunc()};

Regards,
ssh
Mar 24 '07 #3
hey
thnx all
but both r not working...donno y
as per the code

var seventhCell = newRow.insertCell(6);
var imgElement = document.createElement("img");
imgElement.src = "Delete.jpg";
imgElement.onClick = clickFunc(); //here is the problem.
seventhCell.appendChild(imgElement);

"Delete.jpg" is present in the same folder as the JSP..
but still the image is not shown..
also i tried the sattic path but not working..

as per ur suggestion i tried both ways to set onclick property
but both r not wotking..
Mar 26 '07 #4
acoder
16,027 Expert Mod 8TB
Try onclick with a lower-case "c".
Mar 26 '07 #5
tht was so silly of me...
thnx a lot....it worked...
but the image is not yet displayed...
wot cud b the reason..???
Mar 26 '07 #6
well its done..
i gave the wrong path...
thnx all bye
Mar 26 '07 #7
acoder
16,027 Expert Mod 8TB
Glad you got it working.
Mar 26 '07 #8

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

Similar topics

3
by: Jim Mitchell | last post by:
I have some code behind that generates 10 imagebutton controls.... I can not seem to figure out how to trap the onclick event for each image and determine which image was clicked. Can someone...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
8
by: cool2005 | last post by:
I tried to dynamically add/clone a <tr> from an existing <tr> to a <table> but the problem is that I need to have a "onclick" event handler in the <tr>. I have tried following A. approach...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
4
by: Mark Rae | last post by:
Hi, VS.NET 2003 on WinXPPro, both with all the latest patches and updates, etc... I've got a very simple WebForm which is used either to add a new record to a SQL Server database or edit a...
9
by: Donius | last post by:
Hey everyone, i am doing some stuff where i'd like to pop up a little confirmation before a user clicks on a 'delete' link. Just trying to keep the markup clean, i added an attribute ...
4
by: manu3d | last post by:
Hi everybody, I'm generating some DIVs dinamically, inclusive of an event function to run when the user clicks on them. While the following lines work perfectly in FF 1.5, I.E. 6.0 ignores...
11
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.