Forum Moderators: open
currently i am using the following javascript, but it has some flaws...
<!-- BEGIN SCRIPT -->
<HEAD>
<style type="text/css"><!--
.vcblist {
background-color: #0000ff;
color: #33CCFF;
font-family: arial;
}
--></style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function SelObj(formname,selname,textname,str) {
this.formname = formname;
this.selname = selname;
this.textname = textname;
this.select_str = str ¦¦ '';
this.selectArr = new Array();
this.initialize = initialize;
this.bldInitial = bldInitial;
this.bldUpdate = bldUpdate;
}
function initialize() {
if (this.select_str =='') {
for(var i=0;i<document.forms[this.formname][this.selname].options.length;i++) {
this.selectArr[i] = document.forms[this.formname][this.selname].options[i];
this.select_str += document.forms[this.formname][this.selname].options[i].value+":"+
document.forms[this.formname][this.selname].options[i].text+",";
}
}
else {
var tempArr = this.select_str.split(',');
for(var i=0;i<tempArr.length;i++) {
var prop = tempArr[i].split(':');
this.selectArr[i] = new Option(prop[1],prop[0]);
}
}
return;
}
function bldInitial() {
this.initialize();
for(var i=0;i<this.selectArr.length;i++)
document.forms[this.formname][this.selname].options[i] = this.selectArr[i];
document.forms[this.formname][this.selname].options.length = this.selectArr.length;
return;
}
function bldUpdate() {
var str = document.forms[this.formname][this.textname].value.replace('^\\s*','');
if(str == '') {this.bldInitial();return;}
this.initialize();
var j = 0;
pattern1 = new RegExp("^"+str,"i"[smilestopper]);
for(var i=0;i<this.selectArr.length;i++)
if(pattern1.test(this.selectArr[i].text))
document.forms[this.formname][this.selname].options[j++] = this.selectArr[i];
document.forms[this.formname][this.selname].options.length = j;
if(j==1){
document.forms[this.formname][this.selname].options[0].selected = true;
//document.forms[this.formname][this.textname].value = document.forms[this.formname][this.selname].options[0].text;
}
}
function setUp() {
obj1 = new SelObj('menuform','itemlist','entry');
// menuform is the name of the form you use
// itemlist is the name of the select pulldown menu you use
// entry is the name of text box you use for typing in
obj1.bldInitial();
}
function handleEnter (field, event) {
var keyCode = event.keyCode? event.keyCode : event.which? event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}
// End -->
</SCRIPT>
</HEAD>
<BODY OnLoad="javascript:setUp();document.menuform.entry.focus()" bgcolor="#0000ff" text="#33CCFF" link="#33CCFF" alink="#33CCFF" vlink="#33CCFF">
<center>
<form name="menuform">
<h2><font color="#00FFFF" face="arial, helvetica"><strong>English to German dictionary</strong></font></h2>
<p><font face="arial, helvetica" size="-1">Please enter the first few letters
of the word you are looking for.</font> <br>
<br>
Search term:
<input type="text" name="entry" size="30" onKeyUp="javascript:[smilestopper]obj1.bldUpdate();" class="vcblist" onkeypress="return handleEnter(this, event)">
</p>
<p><br>
<select name="itemlist" class="vcblist" size=5 onchange=document.menuform.word.value=document.menuform.itemlist[document.menuform.itemlist.selectedIndex].value onkeypress="return handleEnter(this, event)">
<option value="ein(e)">a</option>
<option value="können">able: to be able to</option>
<option value="gegen">about</option>
<option value="weiterkommen">advance, to</option>
<option value="der Vorteil,-e">advantage</option>
<!-- there are hundreds of words but this gets the point across --> </select>
<textarea name="word" cols="30" rows="4" class="vcblist" onkeypress="return handleEnter(this, event)"></textarea>
</p>
<p>*Seperable prefix</p>
</form>
</center>
<!-- END SCRIPT -->
the script uses a very interesting way of searching the vocab list but sometimes returns incorrect results.
i would GREATLY appreciate if anyone would either debug this script or provide an alternative
Thank you
<!-- end list -->
when you search a term such as this one
<option value="der arm,-e">arm</option>
OR
<option value="der Nachmittag,-e">afternoon</option>
the value is often returned as one "-e" rather than "der arm, -e"
it aslo seems to have problems with refreshing the page and the use of the enter key to submit the form... i solved the later by adding a bit that uses the enter key to just switch fields but i have been unable to discover why everything else is happening