473,467 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

create event -property

Ciary
247 Recognized Expert New Member
hi all,

i have another problem. in my website, i have an option to create divs dynamically. the problem is that i want to do something when you click on one of those divs. i thought this would do the trick
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("MyDiv").onClick = "MyFunction()"
unfortunatly, it doesn't. :(

does anyone know how it should be done?
Apr 9 '09 #1
5 1386
acoder
16,027 Recognized Expert Moderator MVP
Try:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("MyDiv").onclick = MyFunction;
Apr 9 '09 #2
Ciary
247 Recognized Expert New Member
ok, that works. but now i need to send an argument when i execute the function.

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("MyDiv").onclick = MyFunction('foo');
this doesn't seem to work since it triggers the event when i create it but not when i click on the div.
Apr 9 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
You need to set it to a function object rather than a function call which is why I removed the parenthesis earlier. Try this:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("MyDiv").onclick = function() {MyFunction('foo');}
Apr 9 '09 #4
Ciary
247 Recognized Expert New Member
acoder, you're the best. :)

ty so much
Apr 9 '09 #5
acoder
16,027 Recognized Expert Moderator MVP
You're welcome :) Glad to help.
Apr 9 '09 #6

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

Similar topics

15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
17
by: Chris Podmore | last post by:
When I perform: EventLog.WriteEntry(strSource, strEntry, EventLogEntryType.Error, intEventID) The event viewer reports The description for Event ID ( 234 ) in Source ( Siclops_WS_Mobile )...
3
by: JohnR | last post by:
I have a form with a number of text boxes, comboboxes etc. What I would like to do is create an event handler for the "mouseenter" event for each of the controls whereby I display information...
2
by: Boki | last post by:
Hi All, We can process the mouse/keyboard events by handling, however, how to create a event on a target form ( ex: webbrowser ) ? Thanks! Best regards, Boki.
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.