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

create event -property

Ciary
247 Expert 100+
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 1385
acoder
16,027 Expert Mod 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("MyDiv").onclick = MyFunction;
Apr 9 '09 #2
Ciary
247 Expert 100+
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 Expert Mod 8TB
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 Expert 100+
acoder, you're the best. :)

ty so much
Apr 9 '09 #5
acoder
16,027 Expert Mod 8TB
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.
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
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
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...

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.