From: Regena on
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?

From: mick white on
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
From: Thomas 'PointedEars' Lahn on
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
From: Randy Webb on
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/
From: Thomas 'PointedEars' Lahn on
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
 |  Next  |  Last
Pages: 1 2
Prev: javascript:false
Next: innerHTML vs. replaceChild()