473,788 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic image id

I have been trying to create a dynamic id for a number of images in a
table so that I can identify which image was clicked on later. ie I
need to set a variable to the id of each image, that is generated by a
loop. The info is read from an XML file in another function and each
section of info is stored as a separate object; Each object is
pertaining to one row in the table.

function createTable ()
{
var output, dynamId;
output="<table id=thisTableId> <TR><TH>..... < \/ TH><\/ TR>" ;

//length is a number given earlier, containing the
//number of rows that need to be in the table

//object is an array of objects, each object containing
//information i want shown in the table

for (var count = 0; count < length; count++)
{
dynamID="img"+ count;
output+= "<TR><TD><i mg src='images\\li ttlex.gif' id=dynamID
onClick=work(id )><\ /img><\/ TD>";

//showing the data in the columns
output+= '<TD class=content>' + object[count].name + '<\/ TD>' +
'<TD class=content align=center>' +
object[count].region +
'<\/ TD><\/ TR>';
}

output += "<\/ table>";
}

function work (num)
{
alert (num);
}

My goal is to have an image clickable in each row of the table in the
left column, except for the header. The image should provide some
indication of what row it is located in. This information will be used
to change the information in another cell of the same row, but i know
how to do that part. The various combinations I have tried, generally
return [null], [object] or the last id no matter which image is
pressed. If needed, it is possible to put more variables into the
object.

Any suggestions would be helpful. Thanks in advance

May 26 '06 #1
5 2391
Camet wrote:
I have been trying to create a dynamic id for a number of
images in a table so that I can identify which image was
clicked on later. ie I need to set a variable to the id
of each image, that is generated by a loop. The info is
read from an XML file in another function and each section
of info is stored as a separate object; Each object is
pertaining to one row in the table.

function createTable ()
{
var output, dynamId;
output="<table id=thisTableId> <TR><TH>..... < \/ TH><\/ TR>" ;

//length is a number given earlier, containing the
//number of rows that need to be in the table

//object is an array of objects, each object containing
//information i want shown in the table

for (var count = 0; count < length; count++)
{
dynamID="img"+ count;
output+= "<TR><TD><i mg src='images\\li ttlex.gif' id=dynamID
onClick=work(id )><\ /img><\/ TD>";

<snip>

There is nothing in javascript that will examine a string literal for a
sequence of charters and substitute another character sequence for it.
(For the overly pedantic: String.prototyp e.replace does not act upon
string literals, and is no help here anyway).

So when the character sequence 'dynamID' is used in the string above it
is just that literal character sequence, uninfluenced by the current
value of any local variable with the name 'dynamID'. If you want to
inset the current value of the variable - dynamID - into the string you
would have to construct a string including that value, by concatenation
(or similar means):-

dynamID="img"+ count;
output+= "... <img src='...' id='"+dynamID+" ' onClick=work(id )> ...";

Incidentally, the onclick handler created from - work(id) - is going to
have to resolve - id - against its scope chain, and finding the IMG
element with the significant ID on that scope chain is non-standard and
not universally supported. Reading the ID of the IMG element as -
this.id - will be more generally effective.

It is also necessary to put quote marks around attribute values in HTML
when they contain characters that are not allowed in unquoted
attributes. Javascript source code in event handling attribute values
almost never qualifies as suited for not being quoted.

Also, in HTML IMG elements must not have closing tags, and all those
extra spaces in your closing tags are very likely to confuse browsers.

Richard.
May 28 '06 #2
Richard Cornford wrote:
There is nothing in javascript that will examine a string literal for a
sequence of charters and substitute another character sequence for it.
(For the overly pedantic: String.prototyp e.replace does not act upon
string literals, and is no help here anyway).


Huh?

"foo".repla ce(/o/g, "bar") // "fbarbar" in any ES Ed. 3 implementation
PointedEars
--
Bill Gates isn't the devil -- Satan made sure hell
_worked_ before he opened it to the damned ...
May 28 '06 #3
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
There is nothing in javascript that will examine a string
literal for a sequence of charters and substitute another
character sequence for it. (For the overly pedantic:
String.prototyp e.replace does not act upon string literals,
and is no help here anyway).


Huh?

"foo".repla ce(/o/g, "bar") // "fbarbar" in any ES Ed. 3
implementation


The dot operator implicitly type-converts its right hand side operand
into an object, where string primitives become String objects.

Richard.
May 28 '06 #4
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
There is nothing in javascript that will examine a string
literal for a sequence of charters and substitute another
character sequence for it. (For the overly pedantic:
String.prototyp e.replace does not act upon string literals,
and is no help here anyway).


Huh?

"foo".repla ce(/o/g, "bar") // "fbarbar" in any ES Ed. 3
implementation


The dot operator implicitly type-converts its right hand side operand
into an object, where string primitives become String objects.


ACK. But to be "overly pedantic": You did not say "string value", you
said "string literal" :)
PointedEars
May 29 '06 #5
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
There is nothing in javascript that will examine a string
literal for a sequence of charters and substitute another
character sequence for it. (For the overly pedantic:
String.prototyp e.replace does not act upon string
literals, and is no help here anyway).

Huh?

"foo".repla ce(/o/g, "bar") // "fbarbar" in any ES Ed. 3
implementation
The dot operator implicitly type-converts its right hand side
operand into an object, where string primitives become String
objects.


ACK. But to be "overly pedantic": You did not say
"string value",


I probably should have said "string primitive".
you said "string literal" :)


In the context of excluding them, which is not false, if not completely
precise.

Richard.
May 29 '06 #6

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

Similar topics

2
13455
by: Sam | last post by:
Hello everyone, I have a table, which contains a picture column, I put URL info into it. "www.myweb.com/1.jpg..." I want to show this picture in my crystal report, I find some samples show the "static" picture in Crystal report, No "Dynamic" one. Can Crystal Report do that? Thanks in advance. Sam
0
1519
by: Michael Huhn | last post by:
I have a web page default.aspx and a dynamic image image.aspx. Image gets parameters via querystring and outputs a gif. Using JavaScript I reload the image with changed parameters quite often. Sometimes it happens that the image does not appear (red cross instead) or that ie keeps loading for minutes. Opening that image in another browser gives me a "403.9: too many connections". Does iis create a new connection on every reload of that...
5
4396
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK' print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Python Dynamic Image Creation Test</TITLE></HEAD>'
3
2723
by: JOSEPHINE ALVAREZ | last post by:
I have this code that I want to use to do a rollover. However, because the company I am doing it for is continually changing the text, I want to be able to use dynamic text to change the text on the fly, and still have the rollover work. I have taken the text off of the buttons, but cannot figure out how to do it with dynamic text using javascript and html. For example, in the columns of this row, I want to put "About...
0
2780
by: UtilityWarrior | last post by:
If you use Visual Basic 6 or VB.net and want to create PDFs from images royalty free then this DLL is for you. The Image to PDF Dynamic Link Library (DLL) will convert one or more images (JPEG, TIFF, PNG, GIF, BMP, PCX and TGA) into a PDF document. Supports multi-image TIFFs and animated GIFs. You can add clickable image stamps (eg company logo to web site), passwords, bookmarks and can even create simple full screen PDF slideshows -...
11
3058
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
9
2986
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I got the core of the javascript from here: http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm I noticed in the demo that sometimes the content takes a long
7
2374
by: dino d. | last post by:
Hi- I want to create a dynamic image with areas so that when the user clicks different areas, the user jumps to those pages. The problem is, I can't seem to figure out how to do this efficiently. Suppose I have a table,items in a database: itemid description count So, basically, I want to create an image that has 3 ovals, representing the top 3 occurring items (with the highest count) in
1
4660
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3501
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
9656
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
9498
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
10364
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
9967
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
8993
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
7517
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
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
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

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.