PDA

View Full Version : :: setting values of select box based on variables ::


babelfish
11-19-2002, 11:11 AM
http://www.simonsgroup.com/test/packages/default.htm

ok, so u do a search using one or more of the options and submit create list compiles and displays the list..

BUT im using this code to show the search criteria that the user just used:

function addVars() {
var f = window.document.listings;
if (pageVars==0) {
f.package.options[f.package.selectedIndex].value=package;
f.package.options[f.package.selectedIndex].text=package;
f.zone.options[f.zone.selectedIndex].value=zone;
f.zone.options[f.zone.selectedIndex].text=zone;
f.doctype.options[f.doctype.selectedIndex].value=doctype;
f.doctype.options[f.doctype.selectedIndex].text=doctype;
}
}

thanks

Roelf
11-19-2002, 11:54 AM
Loop through the options of the three selectboxes until the value of the option equals the value stored in the variables: package, zone and doctype. then set the selected property of that option to true

babelfish
11-19-2002, 12:01 PM
:thumbsup: how would i go about doing that? :confused:

glenngv
11-19-2002, 12:07 PM
you don't want to change the value and text properties
you only want to select the previous criteria.


function addVars() {
var f = window.document.listings;
if (pageVars==0) {
selectOption(f.package,package);
selectOption(f.zone,zone);
selectOption(f.doctype,doctype);

}
}

function selectOption(objSelect,item){
for (var i=0;i<objSelect.options.length;i++){
if (objSelect.options[i].value==item){
objSelect.selectedIndex = i;
break;
}
}
}

babelfish
11-19-2002, 12:38 PM
thats the fella - thx guys (and gals)