Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts

    paste into text field of a form from hyperlink choice

    Hi

    If I had a list of images for a user to select from, is there any way of using javascript to insert the image address into a text field of a html form, once the image has been clicked?

    Code:
    <form action="self.html" method="post">
    <a href="#"><img src="image1.gif" /></a>
    <a href="#"><img src="image2.gif" /></a>
    <a href="#"><img src="image3.gif" /></a>
    <a href="#"><img src="image4.gif" /></a>
    <input name="imagechosen" type="text" value="image(1,2,3 or 4).gif" />
    </form>
    There are about 20 images to be selected in all.
    Unfortunately I have no experience with javascript and images cannot be used in a list/menu of a form.
    Thanks for your time!
    Last edited by Trinity-Links; 01-05-2009 at 11:47 AM. Reason: update

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    What's your ultimate aim after all? Do you need to save those selected images in somewhere?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts
    no...

    this is just a small snipet of a larger form....

    I am creating a css menu maker and have about 20 background gradiants for users to choose from.
    Once the user has selected the image to use, the form is submitted (hopefully with the image name in the text field) and I use PHP to tweak the CSS menu code

    Code:
    <style>
    .mmenu a{ background: url(<? echo $imagename; ?>) no-repeat top left;}
    </style>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,920
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    There may be a more elegant solution but this will work fine (and of course the value in the chosen box is available for use elewhere):-

    Code:
    <form action="self.html" method="post">
    <a href="#"><img src="image1.gif" onclick = "document.getElementById('chosen').value = 'image1.gif'"></a>
    <a href="#"><img src="image2.gif" onclick = "document.getElementById('chosen').value = 'image2.gif'"></a>
    <a href="#"><img src="image3.gif" onclick = "document.getElementById('chosen').value = 'image3.gif'"></a>
    <a href="#"><img src="image4.gif" onclick = "document.getElementById('chosen').value = 'image4.gif'"></a>
    
    
    <input name="imagechosen" type="text" id = "chosen" value="" />
    </form>


    "A weak currency reflects a weak econony and a weak government". - Gordon Brown, now the UK Prime Minister, 1997.

  • Users who have thanked Philip M for this post:

    Trinity-Links (01-05-2009)

  • #5
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Worked a treat!

    Thanks 4 your time..

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I'd recommend you to use radio buttons along with those images, to record the selected one correctly even if there is no javascript. (Thus you may avoid that text field)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,920
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by abduraooft View Post
    I'd recommend you to use radio buttons along with those images, to record the selected one correctly even if there is no javascript. (Thus you may avoid that text field)
    Well, yes, you are quite right in one way but if Javascript is not enabled all bets are off anyway, and this forum has little purpose. But the OP did specify that he wanted the image address inserted into a text field.
    Last edited by Philip M; 01-05-2009 at 01:08 PM.

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by Philip M View Post
    Well, yes, but if Javascript is not enabled all bets are off anyway, and this forum has little purpose.
    I meant, if it's purely a client-side requirement, javascript is enough. But the OP's case includes submitting a form and processing the posted data. That's why I asked the 'ultimate aim' first
    Last edited by abduraooft; 01-05-2009 at 01:35 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •