473,804 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UI: assignment of links using onclick event handler

Comrades:

Am trying to build a UI widget. I'm sure part of the problem is proper
variable scope or object reference, and part of the problem may be the
way I'm calling the function, but, here goes.

Part I. Consider:

A B C D M
E F G H N O
I J K L

where A...L are linked thumbnails, the links go to "#",
M is a large image, and
N and O are left and right buttons.
All objects are absolutely positioned.

For now we'll consider O's case only. When O is clicked, this will
trigger a function that retrieves values from an array of thumbnail
objects that has a small and big image reference, and assigns a new src
to thumbnails A...L via getElementById( '...').src.

for (var i = 0; i < 12; i++) {
var newthumb = "thumb" + i; // to retrieve the thumbnail properties in
the array
var thumbref = "'img" + i + "'"; // this is the ref for A...L
var newbigimg = newthumb.bigimg ; // tells the thumbnail what to set M
to when clicked
document.getEle mentById(thumbr ef).src = newthumb.smalli mg; // sets
A...L's new src
...
}

Where I'm stuck is, how to tell the thumbnail's link to change M
through getElementById( '...').onclick. Currently I'm passing it an
anonymous function call, like this:

document.getEle mentById(thumbr ef).onclick = function () {
document.getEle mentById('bigim age').src = newbigimg; }

But, because of the for loop, when I click a thumb, they all only
change M's src to the very last image in the array, 11.jpg. I think it
is because when the loop ends, all the links call the same anon
function, and the last ref for newthumb.bigimg is 11.

I speculate, therefore, that to solve this problem, I need to be able
to assign a separate function to each link, whereby A's link's onclick
property calls a function that turns M's src to "1.jpg", B's link's
onclick property turns M's src to "2.jpg", etc. Should I store the
function in the array as a literal value? Hmm.

Part II. My desperate plea for help:
If anyone can tell me how I can set the link's onclick property for
each thumbnail with a separate argument, I'd greatly appreciate it.

Many thanks in advance. (Unconstructive code crit and other forms of
hating notwithstanding . ;-))
Cheers,
DM

Jul 23 '05 #1
1 2176
Lee
Dark Magician said:

Comrades:

Am trying to build a UI widget. I'm sure part of the problem is proper
variable scope or object reference, and part of the problem may be the
way I'm calling the function, but, here goes.

Part I. Consider:

A B C D M
E F G H N O
I J K L

where A...L are linked thumbnails, the links go to "#",
M is a large image, and
N and O are left and right buttons.
All objects are absolutely positioned.

For now we'll consider O's case only. When O is clicked, this will
trigger a function that retrieves values from an array of thumbnail
objects that has a small and big image reference, and assigns a new src
to thumbnails A...L via getElementById( '...').src.

for (var i = 0; i < 12; i++) {
var newthumb = "thumb" + i; // to retrieve the thumbnail properties in
the array
var thumbref = "'img" + i + "'"; // this is the ref for A...L
var newbigimg = newthumb.bigimg ; // tells the thumbnail what to set M
to when clicked
document.getEle mentById(thumbr ef).src = newthumb.smalli mg; // sets
A...L's new src
...
}

Where I'm stuck is, how to tell the thumbnail's link to change M
through getElementById( '...').onclick.


They should each have exactly the same onclick event handler.
Design that event handler so that it does the appropriate
thing depending on which image was clicked and the current
value of some attribute of that image.

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
9943
by: Yvan J. Gagnon | last post by:
I am currenly developing a web site using Macromedia fireworks, and am trying to figure out a way (through hand-coding) of attaching a javascript function (onClick="doit=false") to each of the links in my fireworks-generated dhtml popup menus. Does anyone here know where I would add this javascript fucntion in the code so that it would be recognized? And do I do it in the html, or in the JS file? The javascript function I need to add is...
16
2624
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class, but I would like to use internally my own = operator for some of my value types, so I can say "x = y;" rather than "x.Assign(y);". The op_Assign operator seems impossibly broken since it takes __value copies of the two objects. Perhaps there is...
10
4325
by: bbcrock | last post by:
does anyone have sample code to display a pop up when a user leaves the site? I really don't want to use this technique, but the clients demand it. I'm thinking something like un body onunload, catch the URL they're linking to and parse it for our own site's url and only display the pop up if they're different. anyone have a sample of that code? anyone know if it's a lousy technique? I'm open to suggestions.
2
18584
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 } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
5
8820
by: chris.poirier | last post by:
Does anyone know how I could make an iframe so that the links in the frame page are disabled ... or if this is possible? Any help is appreciated.
26
8128
by: johkar | last post by:
I need to cancel the link and execute a function onclick of all the links within the span tag which has a class of "container" assigned. There will be only one span tag with this class applied. I know you can get a specific tag using document.getElementsByTagName('span'), but I am unsure how to get the one with the class="container". I know there is a getAttribute method, just need a pointer or two to put it all together. Once I know...
4
13571
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of image is fired with event.keyCode as undefined. I was expecting that the form would get submitted. I tried returning from onclick() handler if keyCode is null, but the
6
1830
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool. One of the requirements is that the calendar will need to display a varying number of months (1..3)
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10087
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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 we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.