View Full Version : passing info from a pull down menu

08-13-2004, 09:04 PM
I am a newbie with a newbie question. I have a pull down menu with names in it. I have a button beside the menu called "select". I also have empty text fields. I want to be able to select a users name in the menu and press the "select" button and have it pass the name into one of the blank text fields.

Basically I have been doing javascript for two days now, and I know how to make a pulldown menu and I know how to make a button. I just don't understand how I can define say optionX in the menu to something that I could then use an event (i think) along with onClick to say set optionX as a stringX, and then I don't know how to say put stringX into this text field.

I tried looking for example of this type of code online and failed. Also, keep in mind i'm not really knowledgeable at all when it comes to setting up the script stuff that usually goes in the <head> tags. Any help would be greatly, greatly appreciated.

08-13-2004, 10:51 PM
Hello and welcome here!

Firstly, I think your description of your problem is good, then only other thing that might help is the HTML of your form (without the Javascript obviously as that's what we'll help you create).

If we can see the HTML, then we know the structure and can get a confirmation of your problem description. From there, I think we will introduce the DOM to you, as it will help you to achieve your goal.


08-14-2004, 03:06 AM
<script type="text/javascript">

function getVal(){

var doc = document['oFrm'];
doc['oTxt'].value = doc['oSel'].options[doc['oSel'].selectedIndex].text;



<form name="oFrm">
<select name="oSel">
<option value="oName1">Matthew</option>
<option value="oName2">Mark</option>
<option value="oName3">Luke</option>
<option value="oName4">John</option>
</select>&nbsp;<input name="oTxt" type="text" size="15" />&nbsp;<input name="oBtn" type="button" value="select" onclick="getVal();" />