1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Fill Input box on Clicking Image

Discussion in 'JavaScript' started by ridesign, Apr 22, 2010.

  1. #1
    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):

     
    ridesign, Apr 22, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    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):
     
    s_ruben, Apr 22, 2010 IP
    ridesign likes this.
  3. ridesign

    ridesign Peon

    Messages:
    294
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, just what i needed
     
    ridesign, Apr 23, 2010 IP