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

LVL 1
megninAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
Try this :


<select name="ActivityList" id="ActivityList" size="1" onchange="$('#ActivityCode').val(this.value)">

Open in new window

0
 
leakim971PluritechnicianCommented:
(it replace line 6)
0
 
HainKurtSr. System AnalystCommented:
no jQuery option:

<select name="ActivityList" id="ActivityList" size="1" onChange="document.getElementById('ActivityCode').value=this.value">
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
megninAuthor Commented:
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. ;-)
0
 
megninAuthor Commented:
HainKurt, thank you for the no jQuery option!

What does the size="1" attribute in my <select /> object do?
0
 
leakim971PluritechnicianCommented:
0
 
megninAuthor Commented:
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. ;-)
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.