Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2009, 11:44 AM   PM User | #1
Trinity-Links
New Coder

 
Join Date: Mar 2008
Location: Leuchars, Scotland, UK
Posts: 51
Thanks: 19
Thanked 0 Times in 0 Posts
Trinity-Links is an unknown quantity at this point
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
Trinity-Links is offline   Reply With Quote
Old 01-05-2009, 11:50 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
What's your ultimate aim after all? Do you need to save those selected images in somewhere?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-05-2009, 11:57 AM   PM User | #3
Trinity-Links
New Coder

 
Join Date: Mar 2008
Location: Leuchars, Scotland, UK
Posts: 51
Thanks: 19
Thanked 0 Times in 0 Posts
Trinity-Links is an unknown quantity at this point
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>
Trinity-Links is offline   Reply With Quote
Old 01-05-2009, 12:00 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Trinity-Links (01-05-2009)
Old 01-05-2009, 12:08 PM   PM User | #5
Trinity-Links
New Coder

 
Join Date: Mar 2008
Location: Leuchars, Scotland, UK
Posts: 51
Thanks: 19
Thanked 0 Times in 0 Posts
Trinity-Links is an unknown quantity at this point
Worked a treat!

Thanks 4 your time..
Trinity-Links is offline   Reply With Quote
Old 01-05-2009, 12:29 PM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-05-2009, 01:04 PM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote
Old 01-05-2009, 01:08 PM   PM User | #8
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 01-05-2009 at 01:35 PM..
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 AM.


Advertisement
Log in to turn off these ads.