Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Build an HTML select list from a table, optionally w/ PK, displayorder & selected
 
  chubbard posted this script:
  // GetSelect - build an html <select>'s <option> list
//
// Parameters:
//    sTbl - the name of the table
//    sFld - the name of the display field
//    sPK - (optional) the name of the field to use as the value attribute
//    sSort - (optional) the name of the field to sort on
//    sSelected - (optional) the field to pre-select
//
// Returns a string (i.e. does not write to response object)
//
// For those occaisions when <ws:select> isn't what you need, this script is
// handy for building the <option> tags of a form's <select> tag.
//
//  Example usage in a view:
//      #var wiz = classes.import("/yourlib.ws");#
//  <form>
// <select name="email">
// #wiz.GetSelect("AddressBook", "email", "rowid", "email", "mike")#
//</select>
//  </form>
//
//  And finally, the actual code:

function GetSelect(sTbl, sFld, sPK, sSort, sSelected)
{
   var sOut = "";
   var selTbl = new cmdSelect(sTbl);
   selTbl.Filter = "*";
   if (null != sSort) selTbl.setSort(sSort);
   var rsTbl = selTbl.execute();
   while (rsTbl.next())
   {
      sOut += "<option";
      if ("" != sPK)
         sOut += " value='" + rsTbl[sPK] + "'";
      if ("" != sSelected &&
          (rsTbl[sPK] == sSelected || rsTbl[sFld] == sSelected))
         sOut += " selected='selected'";
      sOut += ">" + rsTbl[sFld] + "</option>";
   }
   return sOut;
}
 
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us