I want to fill the input box with the image url when I click on an image, but I do not know how to pass the image url using the onclick method. I can pass a number but not the url. <head><script type="text/javascript" language="javascript"><!-- function fill(a) { var MyElement = document.getElementById("imageurl"); MyElement.value = a; return true; } //--></script></head> <body> <img src="http://www.site.com/image.jpg" onclick="fill()" > <img src="http://www.site.com/image2.jpg" onclick="fill()" > <input type="text" id="imageurl" name="imageurl" value=""> </body> Code (markup):
Try this: <head><script type="text/javascript" language="javascript"><!-- function fill(a) { var MyElement = document.getElementById("imageurl"); MyElement.value = a; return true; } //--></script></head> <body> <img src="http://www.site.com/image.jpg" onclick="fill(this.src)" > <img src="http://www.site.com/image2.jpg" onclick="fill(this.src)" > <input type="text" id="imageurl" name="imageurl" value=""> </body> Code (markup):