The following script will autocomplete a text input field with ONCHANGE of the select field
I would like to modify it so that the select fields add to the original value rather than replacing it, i.e.
word1 phrase one
Thanks,
Mike
<SCRIPT>
function matchFieldSelect (field, select, value) {
var property = value ? 'value' : 'text';
var found = false;
for (var i = 0; i < select.options.length; i++)
if ((found = select.options[property].indexOf(field.value) ==
0))
break;
if (found)
select.selectedIndex = i;
else
select.selectedIndex = -1;
if (field.createTextRange) {
var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;"
if (cursorKeys.indexOf(event.keyCode+";"
== -1) {
var r1 = field.createTextRange()
var oldValue = r1.text;
var newValue = found ? select.options[property] : oldValue;
if (newValue != field.value) {
field.value = newValue
var rNew = field.createTextRange()
rNew.moveStart('character', oldValue.length)
rNew.select()
}
}
}
}
</SCRIPT>
Select term to fill in text field
<FORM NAME="aForm">
<SELECT NAME="words" SIZE="1" ONCHANGE="this.form.word.value = this.options[this.selectedIndex].text">
<OPTION>SELECT WORD
<OPTION>word1
<OPTION>word2
<OPTION>word3
<OPTION>word4
</SELECT>
<SELECT NAME="words2" SIZE="1" ONCHANGE="this.form.word.value = this.options[this.selectedIndex].text">
<OPTION>SELECT PHRASE
<OPTION>phrase one
<OPTION>phrase two
<OPTION>phrase three
<OPTION>phrase four
</SELECT><BR><BR>
<INPUT TYPE="text" NAME="word" ONKEYUP="matchFieldSelect(this, this.form.words)" SIZE=25>
</FORM>
I would like to modify it so that the select fields add to the original value rather than replacing it, i.e.
word1 phrase one
Thanks,
Mike
<SCRIPT>
function matchFieldSelect (field, select, value) {
var property = value ? 'value' : 'text';
var found = false;
for (var i = 0; i < select.options.length; i++)
if ((found = select.options[property].indexOf(field.value) ==
0))
break;
if (found)
select.selectedIndex = i;
else
select.selectedIndex = -1;
if (field.createTextRange) {
var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;"
if (cursorKeys.indexOf(event.keyCode+";"

var r1 = field.createTextRange()
var oldValue = r1.text;
var newValue = found ? select.options[property] : oldValue;
if (newValue != field.value) {
field.value = newValue
var rNew = field.createTextRange()
rNew.moveStart('character', oldValue.length)
rNew.select()
}
}
}
}
</SCRIPT>
Select term to fill in text field
<FORM NAME="aForm">
<SELECT NAME="words" SIZE="1" ONCHANGE="this.form.word.value = this.options[this.selectedIndex].text">
<OPTION>SELECT WORD
<OPTION>word1
<OPTION>word2
<OPTION>word3
<OPTION>word4
</SELECT>
<SELECT NAME="words2" SIZE="1" ONCHANGE="this.form.word.value = this.options[this.selectedIndex].text">
<OPTION>SELECT PHRASE
<OPTION>phrase one
<OPTION>phrase two
<OPTION>phrase three
<OPTION>phrase four
</SELECT><BR><BR>
<INPUT TYPE="text" NAME="word" ONKEYUP="matchFieldSelect(this, this.form.words)" SIZE=25>
</FORM>