Hi guys!
I am not Javascript savvy at all and I would like some help from you...
How can I pass the value of a tex box in a drop down menu by clicking a button?
Thanks!
| SitePoint Sponsor |

Hi guys!
I am not Javascript savvy at all and I would like some help from you...
How can I pass the value of a tex box in a drop down menu by clicking a button?
Thanks!
Ginie G.
Ok, your quarterback is the select box. But who's your receiver?
</smartaleck>
Seriously, what do you want to pass this to? A text box? A javascript variable? Another page?

Well, the receiver is ... a drop down menu.
I guess it would be easier to understand if you can actually see what I want to do.
Go to www.travelflip.com/test.htm
Basically, I want my users to build a list of dates (in the drop down menu).
Can you help me out?
Thanks!
Ginie G.
Check out this sample page, and see if you can apply it to yours...Code:<html> <head> <title>untitled</title> <script type="text/javascript" language="javascript"> function addOption(f, sID, val, label) { var o = document.createElement("OPTION"); var t = document.createTextNode(label); o.appendChild(t); o.value = val; f.elements[sID].appendChild(o); } </script> </head> <body> <form> <input type="text" name="date"> <input type="button" value=">>>" onClick="addOption(this.form,'vac_black',this.form.date.value, this.form.date.value)"> <select size="2" name="vac_black"></select> </form> </body> </html>

Thanks a lot!
It worked!
Ginie G.

Hello, me again!
How could I add a "Remove Button" which would a selected option in the drop down menu?
Ginie G.
Let's see if you can figure this one out
The method I recommend for removing nodes is
object.removeChild(childNode);
example:
var s = document.forms[0].elements['vac_black'];
s.removeChild(s.options[2]);
Hint: In a SELECT, the child's index in it's parent's options collection is identical to it's selectedIndex

Well...
Right now, Javascript is like Ancient Chinese to me.
Thank you for showing me the code!
Ginie G.
function removeOption(e) {
e.removeChild(e.options[e.selectedIndex]);
}
<input type="button" value="<<<" onClick="removeOption(this.form.vac_black);">
Bookmarks