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

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><img src='images\\littlex.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 2368
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><img src='images\\littlex.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.prototype.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.prototype.replace does not act upon
string literals, and is no help here anyway).


Huh?

"foo".replace(/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.prototype.replace does not act upon string literals,
and is no help here anyway).


Huh?

"foo".replace(/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.prototype.replace does not act upon string literals,
and is no help here anyway).


Huh?

"foo".replace(/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.prototype.replace does not act upon string
literals, and is no help here anyway).

Huh?

"foo".replace(/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
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...
0
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....
5
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'...
3
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...
0
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,...
11
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
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...
7
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....
1
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...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.