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

Add action listener to different images

I am creating an App for iPhone using JavaScript. I have an array of images, let say img[] ,and a place all these images on screen i want to add action listener to each image. Each image has to perform different functionality. I am using this method

Expand|Select|Wrap|Line Numbers
  1. for(var i=0;i<img.length)
  2. {
  3.    img[i].addactionlistner('click',function(e){
  4.     //Print the index of image clicked
  5. });
  6.  
  7.  
  8. }  
This method add action listener to images.Please tell me that this method is right or not. If yes then how can i identify that which image is clicked(it should tell me the index).
May 14 '13 #1
1 1638
Dormilich
8,658 Expert Mod 8TB
so far only the for() loop is incorrect. there need to be 2 semi-colons inside.

how can i identify that which image is clicked(it should tell me the index)
usually (i.e. in browser JS), in an event handler this points to the element the handler is executed on (that would be the image element).
if that approach does not apply, you have to use a Closure to get the index into the handler function.
May 14 '13 #2

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

Similar topics

17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
9
by: finerrecliner | last post by:
i'm trying to make an action listener that will display an alert box when the user clicks anywhere on the page once, and then go back to normal mouse behavior. i have this: <html><script...
1
by: stagedud | last post by:
At this moment im working on a _MouseMove function, and I have a question about my function. When somebody moves his mouse over the checkbox, a different label shows a description from a database....
0
by: aolba | last post by:
Hello, I hope I could get some help with this issue, since I give up. It is too much for just me. This script is originally from MX. I have a hard time trying to translate to AS3. Anyway. There...
5
by: nt5515 | last post by:
i've just started using java and im trying to develop a GUI that will play a game. i have a start screen with some Jbuttons. The button represent 3 sizes of the game grid, when these are pressed i...
7
by: kalar | last post by:
i make a JFrame window and i add a label i.e. myLabel , which has an image and down from the label a button i.e. dice. I want when i press the button to change the image on the label but when i am...
12
by: K Viltersten | last post by:
When i'm using the following, everything works well. butt1.on ('click', function () {sameStuff ('1')}); butt2.on ('click', function () {sameStuff ('2')}); Now, i wish to compact it into one...
2
by: Hiten | last post by:
Our application is created in C#, ASP.Net 2.0, SQL 2005; the session is managed in SQL server with ASPState. We often file below exception Error Details : Exception of type...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.