Hi - I have a really stupid failure of code, can't figure it out.
Two fields in a form, Textinput and select; if text is written into
input, select changes "selected" to a matching option. This works.
Now I would like to put the WHOLE value of the selected option into
the input field, if the user klicks on something in the select-field.
This DOESN'T work, because I seem not to reference the selected item
correctly.
But then again i did everything according to the various tutorials.
THX for a quick hint.
Code:
___________________
<html>
<head>
<title>Some page</title>
<script language="JavaScript">
<!--javascript:
function selectOption(oTxt){
var sel = oTxt.form.select;
var len = sel.options.length;
sel.selectedIndex = len - 1; //select 'Select One' option by default
for (var i=0; i<len; i++){
if (sel.options[i].value.indexOf(oTxt.value)!=-1){
sel.selectedIndex = i;
break;
}
}
}
//--</script>
<script language="JavaScript">
<!--javascript:
function ChangeField (oTxt){
var stamm = oTxt.form.write;
var sel=oTxt.SelectedIndex;
stamm.value=oTxt.options[sel].value;
}
//--</script>
</head>
<body>
<form name="Anmeldung" method="post" action="anmelden.php">
<input type="text" name="write" size="23"
onkeyup="selectOption(this)" onblur="selectOption(this)" value="">
<select name="select" size="3" onclick="ChangeField(this)">
<option value="A name">A name</option>
<option value="B Name">B name</option>
<option value="C name">C name</option>
<option value="D name">D name</option>
<option value="E name">E name</option>
</select>
</form>
</body>
</html>
___________________