Asking help for a simple application

zyreena

New Member
Messages
57
Reaction score
0
Points
0
is there anyone who tried creating a simple application that uses JavaScript to dynamically update the contents of a text field with the value selected by a drop down (select) menu?

i am new to java scripting too, and got a hard time understanding EVERYTHING im reading. and based on experience its way better for me to understand easily if i am going to analyze the syntax/code of a certain application.

a help will be very much appreciated. tnx in advance
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
More a DOM matter than JS:
HTML:
<form>
<input name="someText" />
<select onchange="setText(this, 'someText')">
<option value="foo">Foo</option>
<option value="bar">Bar</option>
</select>
</form>
<script type="text/javascript">
function setText(from, toName) {
  from.form[toName].value = from.value;
}
</script>
 

OdieusG

New Member
Messages
50
Reaction score
0
Points
0
Easiest way is store values in an array, and just like Mission put, use the onChange and IDs to signify what information it should change to
Here's a small example, by principle. I'm not too adept in javascript, but this should give a general idea, it only displays an alertbox, but from that, you should be able to figure something:
Code:
<script type="text/javascript">
var arr = new Array("Item 1", "Item 2", "Item 3");
function popup() {
	var x=document.getElementById("pulldown").value;
	alert(arr[x]);
}
</script>
<form>
<select id="pulldown" onChange="popup()">
<option value="0">Alpha</option>
<option value="1">Beta</option>
<option value="2">Gamma</option>
</select>
</form>
 

zyreena

New Member
Messages
57
Reaction score
0
Points
0
you two are of really great help. tnx for being so kind. im starting to analyze both codes. GOD BLESS
 
Top