|
<!-- b.dropdown.asp - copyright (c) 2001-2002 by Bj�rnar Henden http://www.bhenden.org/ -->
<script language=javascript runat=server>
function Out(s) {
Response.Write(s);
}
function CreateDropdown(name,rs,idfield,displayfield) {
return new BDropdown(name,rs,idfield,displayfield);
}
function BDropdown(name,rs,idfield,displayfield) {
this._name = name;
this._rs = rs;
this._idfield = idfield;
this._displayfield = (''+displayfield=='undefined') ? BDropdown_GetTextField(rs) : displayfield;
this.Display = BDropdown_Display;
this.GetValue = BDropdown_GetValue;
this.SetValue = BDropdown_SetValue;
this.SetOption = BDropdown_SetOption;
this.IsNull = BDropdown_IsNull;
this._height = 1;
if(Request.Form(this._name).Count==1)
this._value = Request.Form(this._name).Item;
else
this._value = 0;
this._onchangesubmit = true;
}
function BDropdown_GetTextField(rs) {
for(var n=0;n<rs.Fields.Count;n++) {
if(rs.Fields(n).Type==adLongVarChar || rs.Fields(n).Type==adVarChar || rs.Fields(n).Type==adChar)
return n;
if(rs.Fields(n).Type==adLongVarWChar || rs.Fields(n).Type==adVarWChar || rs.Fields(n).Type==adWChar)
return n;
}
return 1;
}
function BDropdown_Display() {
Out("\n<select size=\""+this._height+"\" class=\"bgrid_input\" name=\"" + this._name + "\"");
if(this._onchangesubmit) Out(" onchange=\"this.form.submit()\"");
Out(">\n\t<option/>\n");
if(!this._rs.BOF && !this._rs.EOF) {
this._rs.MoveFirst();
while(!this._rs.EOF) {
if(!this.IsNull(this._rs.Fields(this._idfield))) {
if(this._rs.Fields(this._idfield).Value == this._value)
Out("\t<option selected value=\"" + this._rs.Fields(this._idfield).Value + "\">");
else
Out("\t<option value=\"" + this._rs.Fields(this._idfield).Value + "\">");
if(this.IsNull(this._rs.Fields(this._displayfield)))
Out(" ");
else
Out(this._rs.Fields(this._displayfield).Value);
Out("</option>\n");
}
this._rs.MoveNext();
}
}
Out("</select>\n");
}
function BDropdown_GetValue() {
return this._value;
}
function BDropdown_SetValue(value) {
this._value = value;
}
function BDropdown_IsNull(oField) {
return "" + oField.Value == "null";
}
function BDropdown_SetOption(option,value) {
switch(option) {
case "onchange_submit":
this._onchangesubmit = value;
break;
case "height":
this._height = value;
break;
default:
throw new Error("Unknown option " + option + "!");
}
}
</script>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.