473,387 Members | 1,582 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.

getElementBy...

I have the following code:

<a href="//www.google.com" id="check"><img name="img1"
src='/images/abc.gif' border='0'></a>

onClick action I want to print the image name id of the anchor.
how do I do that where should I add the onClick action in the anchor or
in the image tag?

Feb 6 '06 #1
5 18785
Regena wrote:
I have the following code:

<a href="//www.google.com" id="check"><img name="img1"
src='/images/abc.gif' border='0'></a>

onClick action I want to print the image name id of the anchor.
how do I do that where should I add the onClick action in the anchor or
in the image tag?

What do you mean by "print"? And do you realise that once you click
the link, another document is loaded into your browser window?
Mick
Feb 6 '06 #2
Regena wrote:
<a href="//www.google.com" id="check"><img name="img1"
I presume you mean "http://www.google.com/". The scheme part must not be
omitted if the target domain is a different one, see RFC3986. Therefore,
the above is equivalent to the resource "www.google.com" right below the
DocumentRoot, not to the www.google.com Web site.
src='/images/abc.gif' border='0'></a>
The `alt' attribute is required for the `img' element.
onClick action I want to print
I presume you mean "to display".
the image name id of the anchor.
I presume you mean "the name of the `img' element the `a' element is parent
of".
how do I do that where should I add the onClick action in the anchor or
in the image tag?
If this was a sentence, given the presumptions above, the answer would be

<a href="http://www.google.com" id="check"
onclick="alert(this.firstChild.name);"<img name="img1" src='/images/abc.gif' border='0' alt="abc"></a>

PointedEars
Feb 6 '06 #3
Thomas 'PointedEars' Lahn said the following on 2/6/2006 12:12 PM:
Regena wrote:


<snip>
the image name id of the anchor.


I presume you mean "the name of the `img' element the `a' element is parent
of".


I read it as the ID of the a element that is wrapped around the image.
how do I do that where should I add the onClick action in the anchor or
in the image tag?


If this was a sentence, given the presumptions above, the answer would be

<a href="http://www.google.com" id="check"
onclick="alert(this.firstChild.name);"


onclick=alert(this.id);return false;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 6 '06 #4
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/6/2006 12:12 PM:
Regena wrote:
the image name id of the anchor.

I presume you mean "the name of the `img' element the `a' element is
parent of".


I read it as the ID of the a element that is wrapped around the image.


Fair enough, the blurred wording of the OP definitely allows for that :)
how do I do that where should I add the onClick action in the anchor or
in the image tag?

If this was a sentence, given the presumptions above, the answer would be

<a href="http://www.google.com" id="check"
onclick="alert(this.firstChild.name);"


onclick=alert(this.id);return false;


The attribute value must be quoted here, and "return false;" is neither
necessary nor viable in its current form (since it would disable the link
feature of the element).

Another solution for the latter:

<a href="http://www.google.com/" id="check"><img
name="img1" src='/images/abc.gif' border='0' alt="abc"
onclick="window.alert(this.parentNode.id);"></a>

And for the former:

<a href="http://www.google.com/" id="check"><img
name="img1" src='/images/abc.gif' border='0' alt="abc"
onclick="window.alert(this.name);"></a>

Both are not as downwards compatible as using the `onclick' attribute of the
`a' element instead, though.
PointedEars
Feb 6 '06 #5
sorry! I'm using frames so on click thebottom frame will change and the
image should chnage in the top frame

Feb 6 '06 #6

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

Similar topics

6
by: oeyvind toft | last post by:
I have a frameset consisting of 3 frames: top, left and right. In top frame: body onload calls a js init function to set (or resets) values in textareas etc...in all frames. In right frame: A...
34
by: Steve Horrillo | last post by:
Anyone know where to get a Tool Tips javascript that will pop up a little box when hovered for words that needs more explanation. I'm using Front Page BTW. -- Warmest regards, Steve...
4
by: Ryan Ternier | last post by:
Hello, I have a repeater control that does the following on the ItemDataBound event. It works perfectly, except that when it prints out, the names of the controls aren't what I'd expect. ...
11
by: chrisdude911 | last post by:
i have a video in a html document. i have typed <img dynsrc="My Immortal.mpg"/> in to create a video box. on http://www.acejs.com/scriptsfolder/110003/110003.html it tell me about adding controls...
5
by: den2005 | last post by:
Hi everybody, Problem with dragging effect of resizing is working but having problem with setting a flag to determine if mouse button is click or not. Is there anyone knows how to fixed this? I...
5
by: d3vkit | last post by:
Okay I bet this is the easiest thing to figure out, but I've tried EVERYTHING to no avail. Maybe it's just not possible but I don't see why not. I have a php page which is grabbing content from...
7
by: decren | last post by:
Hello, I have a table with an add-row setup. The table has several columns but I only need to calculate COLUMN FOUR. The results go to a textbox via a button. My code is..... function sumup() { ...
5
by: Ketty | last post by:
Hi Experts, I am trying this bit of code which is not working right. <script language="JavaScript" type="text/JavaScript"> <!-- function showHide(divName) { var x = new getObj(divName);...
4
by: phub11 | last post by:
Hi all, I have started using AJAX to populate drop downs from a mySQL database; however, I want the option of modifying the selected OPTION of the drop down using an array of radiobuttons...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.