...

View Full Version : paste into text field of a form from hyperlink choice



Trinity-Links
01-05-2009, 11:44 AM
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?


<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!

abduraooft
01-05-2009, 11:50 AM
What's your ultimate aim after all? Do you need to save those selected images in somewhere?

Trinity-Links
01-05-2009, 11:57 AM
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



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

Philip M
01-05-2009, 12:00 PM
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):-


<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.

Trinity-Links
01-05-2009, 12:08 PM
Worked a treat!

Thanks 4 your time..

abduraooft
01-05-2009, 12:29 PM
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)

Philip M
01-05-2009, 01:04 PM
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. :D:D But the OP did specify that he wanted the image address inserted into a text field.

abduraooft
01-05-2009, 01:08 PM
Well, yes, but if Javascript is not enabled all bets are off anyway, and this forum has little purpose. :D:D
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum