View Full Version : Populating a form field from a drop down
munkynpunky
09-24-2006, 12:57 AM
Hey guys,
I'm trying to use one drop down menu - and select an item, once selected shows the cost up instantly in a form field nest to the drop down..
There are maximum of 5 items, each with 5 different prices.
i dont know if this is the right forum, but im writting in php, so thought id try here first :)
Thanks for your help
djr33
09-24-2006, 01:10 AM
This isn't php... it's javascript.
The trick here is making the php output the right javascript code. Depending on the complexity of your php, and how much of the html it generates, it could be easy or hard. Hopefully, it's not too hard.
Anyway, for the javascript code itself...
<select onChange="result.value=this.value">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<input type="text" id="result">
Note: You might want to set an initial value in the textfield that matches the pre-selected option in the dropdown.
munkynpunky
09-24-2006, 01:40 AM
This isn't php... it's javascript.
The trick here is making the php output the right javascript code. Depending on the complexity of your php, and how much of the html it generates, it could be easy or hard. Hopefully, it's not too hard.
Anyway, for the javascript code itself...
<select onChange="result.value=this.value">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<input type="text" id="result">
Note: You might want to set an initial value in the textfield that matches the pre-selected option in the dropdown.
Hmmm ok, right, well its basically
year one = 3.25
year two = 6.50
year three = 9.75
and if i select year one i want to see 3.25 in a different readonly box next to the year selection...
munkynpunky
09-24-2006, 01:46 AM
MOVED (http://www.dynamicdrive.com/forums/showthread.php?p=54550#post54550)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.