473,320 Members | 2,020 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,320 software developers and data experts.

attach events to dynamically created elements

54
Hello,
I am able to attach event to dynamically created element.as shown below.

Expand|Select|Wrap|Line Numbers
  1. for(var i=0;i<10;i++)
  2.      {for(var j=0;j<15;j++)
  3.          {     
  4.                var div=document.createElement('div');
  5.                div.setAttribute("name","div"+i+j);
  6.                div.setAttribute("id","div"+i+j); 
  7.                var r=i;var c=j;
  8.                div.attachEvent("onclick",function(){ change_color('div'+i+j)});
  9.               if(i==5 && j==7)
  10.               {
  11.                   div.style.backgroundColor='blue'; //Making the centre one blue;
  12.               }
  13.  
  14.               div.style.left=60+(j*15)+"px";//document.frm_cam_copyset.btn_Set.type         input.type='button';
  15.               div.disabled=true;
  16.               //input.style.backgroundColor='transparent';
  17.               div.style.position="absolute";
  18.               div.style.top=170+(i*15)+"px";
  19.               div.style.width=13+"px";
  20.               div.style.height=13+"px";
  21.               div.style.border="1px  solid #ff0000";              
  22.               p_d.appendChild(div);                        
  23.          }
  24.      }//alert(document.g
  25.  

This code creates a table like look containing div s as cells of the table.this is to enable a perticular area to be selected using onclick event on div.
The problem i'm facing is,
I'm not able to attach the event 'onclick' to thse cells as shown in bold in the code.
change_color() is the function that must be called everytime i click the div.i'm passing the id of the div.
Whenever i pass the id of this div the id of the last element is getting fetched.Please help me
Mar 10 '08 #1
1 1832
gits
5,390 Expert Mod 4TB
hi ...

have a look at this thread where an analogue problem is handled ...

kind regards
Mar 10 '08 #2

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

Similar topics

3
by: Aymer | last post by:
i created a new button object. how do i attach an event on it? thanx for your help. Dim cc As ColorConverter = new ColorConverter() Dim b = new button() b.ID = "SelectedDate" b.BorderStyle...
1
by: Will | last post by:
Hi, I have a problem trying to validate dynamically created html form elements using javascript. I have dynamically created a check box using ASP for each record in a recordset and have given each...
4
by: Julie J. | last post by:
When working w/ forms and controls, in 95% of the cases, the value of the control is used somewhere in the program (duh!). However, there doesn't seem to be an easy way to attach a value variable...
4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
1
by: Bishop | last post by:
I have a page that generates a grid of controls; at the end of each row is an update button that is dynamically created with an associated click event. The grid changes based on the date selected...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
1
by: Nirmalkumar | last post by:
How to attach an event to dynamically created control in VB.NET I have dynamically created dropdown list in code behind (VB.NET). For this control I want to attach an event for action...
7
by: mavigozler | last post by:
IE7 does not appear to set an event on contained text inside SPAN elements whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML recommendation. Firefox appears to conform. ...
2
by: Nathan Sokalski | last post by:
I have LinkButtons that are dynamically created in one of the PostBack events. They must be created in the PostBack event because one of the variables required to determine which ones to create...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.