Link to home
Start Free TrialLog in
Avatar of David Megnin
David MegninFlag for United States of America

asked on

Need to put value from drop down into a text box using JavaScript

I have an ASP.Net web form and I need to add a drop down selector, "ActivityList", that when an item is selected will put the value, e.g. "120" into a text box, "ActivityCode".

It would also be nice, but not necessary, to maintain the list of text and values in an array in the JavaScript.

I'm already using some JavaScript in an external .js file and some jQuery.  They don't seem to always play nice together, so I need to watch for that.

Thanks!
(P.S. I don't really know how to write JavaScript, but I can make minor changes to customize something for my purposes.)
<tr class="NewQuestion">
	<td align="right">
		Activity:
	</td>
	<td>
		<select name="ActivityList" id="ActivityList" size="1">
			<option value="120">Job Search Job Readiness</option>
			<option value="210">Community Service</option>
			<option value="220">Work Experience</option>
			<option value="731">Vocational Training</option>
			<option value="310">Job Skills Training Directly Related</option>
		</select>	
	</td>
	<td>
		<input type="text" name="ActivityCode" id="ActivityCode" />
	</td>
</tr>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(it replace line 6)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Megnin

ASKER

leakim971, oh, that's just too simple.  ;-) And it worked great.

In my reading of "best practices" some post, somewhere, said that scripts should always go into external files, so I was expecting something more complicated.  This looks like a case where "Best Practices" may be overkill, when "simple" works just fine.

I saw another comment come in just now, so I'll go read that one.  I would still like to get a script that uses an array for the list so I can use it in future projects as well. ;-)
HainKurt, thank you for the no jQuery option!

What does the size="1" attribute in my <select /> object do?
Oh!, cool.

I love those w3shools.com "Try it yourself" examples!!!

Thank you both for the nice simple script!!!  I'm learning, so the complicated code can be frustrating. ;-)
You're welcome! Thanks for the points!