Hello guys, I have a very simple problem for you to solve. It's not simple for me but it's probably very easy to you guys. I've tried searching this but failed.
Anyway, here is my problem. I have an image. When I call a function with onclick, I pass the image's id. My problem is that when I click the image, it displays "undefined". It is supposed to display the value of the image. It works perfectly fine in internet explorer. Its firefox that's giving me the problem. Can you guys give me the code for firefox so I can adjust? Please tell me why it won't work also. kthx

html code:

<img src="Lighthouse.jpg" class="card" id="card1" value="50" onclick="reveal('card1')">

javascript code

function reveal(id)
6 Years
Discussion Span
Last Post by Whilliam

You can simplify the onclick by passing this (which references the triggering element). Then use the getAttribute("value") on that element.

<img src="Lighthouse.jpg" class="card" id="card1" value="50" onclick="reveal(this)" />
function reveal(card)
    var value = card.getAttribute("value");

Images don't really have a value so you need to use Get Attribute instead which will grab any attribute you place on an element (it shouldn't work in IE either but that's IE).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.