Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: help required on pulldown menu


Message #1 by "mike ball" <mike@c...> on Wed, 18 Apr 2001 18:27:29
Hi,

Below is a code to enable people to view the subjects on all pages.

In NN it the words appear in text box in IE they do not. Also though I 
input the correct html field it will not send me to that page.

I am using Adobe GoLive V5.

I am also confused that when I include script that works on 1 page and copy 
it across to another page 9x10 it fails.

Any help would be gratefully received.

Mike
<HEAD>

<SCRIPT LANGUAGE="JavaScript">


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");
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(); 
}
//  End -->
</script>
</HEAD>


<BODY OnLoad="javascript:setUp()">


<center>
<form name="menuform" onSubmit="javascript:window.location = 
document.menuform.itemlist.options[document.menuform.itemlist.selectedIndex
].value;return false;">

<font face="arial, helvetica" size="-1">Please enter the first few letters 
of the item you are looking for.</font>
<br><br>
<input type="text" name="entry" size="30" 
onKeyUp="javascript:obj1.bldUpdate();">
<br>
<select name="itemlist" size=5>
<option value="airportspage.html">Airports
<option value="airlinespage.html">Airlines
<option value="page.html">C

</select>
</form>
</center>
</bo

  Return to Index