I have been having a lot of trouble trying to get value into javascript and pass it to alert. Here is the code that I use to pass the value....
<img onclick="handpost()" id="colorface" name="red" src="http://www.asl-ela.org/image/redface.png" alt="Red face" /></a>
Then I use function to get the data from img tag....
<script type="text/javascript">
function handpost() {
var color = document.getElementById('colorface').name;
alert(color);
}
</script>
I keep getting alert box saying undefined. What does that mean?!?!?!
It means exactly what it reads: document.getElementById('colorface').name is undefined. document.getElementById('colorface') may exist but it doesn't have property name. Try document.getElementById('colorface').getAttribute('name').
name is not standard attribute of img but if you add it then you can access it.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With