The function listed below, jsBindData(), depends on HTML similar to the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <LINK REL=stylesheet TYPE="text/css" HREF="./root.css"> <META NAME=Generator CONTENT="Bryan Wilhite"> <META NAME=Reply-To CONTENT="rasx@kintespace.com"> <META NAME=Keywords CONTENT="Songhay System, email, kinte space"> <META NAME=Description CONTENT="Email List"> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="./root.js"></SCRIPT> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="./email.js"></SCRIPT> <TITLE>Songhay System: Email List</TITLE> </HEAD> <BODY BACKGROUND="http://Songhay3/kRoot/bitmaps/backgrnd.gif" BGCOLOR=Black TEXT=White LINK=Lime VLINK=Silver ALINK=Yellow onLoad="jsFormat()"> <!-- RDS.DataControl Objects: --> <OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33" ID=dsoEmail HEIGHT=0 WIDTH=0> <PARAM NAME=Connect VALUE="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=kinteDB;Data Source=SONGHAY3"> <PARAM NAME=Server VALUE="http://Songhay3"> <PARAM NAME=SQL VALUE="EXECUTE ListDSOEmail"> </OBJECT> <OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33" ID=dsoEmailTypes HEIGHT=0 WIDTH=0> <PARAM NAME=Connect VALUE="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=kinteDB;Data Source=SONGHAY3"> <PARAM NAME=Server VALUE="http://Songhay3"> <PARAM NAME=SQL VALUE="EXECUTE ListDSOEmail 1"> </OBJECT> <OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33" ID=dsoEmailFilter HEIGHT=0 WIDTH=0> <PARAM NAME=Connect VALUE="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=kinteDB;Data Source=SONGHAY3"> <PARAM NAME=Server VALUE="http://Songhay3"> <PARAM NAME=SQL VALUE="EXECUTE ListDSOEmail 2"> </OBJECT> <TABLE WIDTH=512 BORDER=0 CELLSPACING=0 CELLPADDING=4 ALIGN=center> <TR> <TH ALIGN=left NOWRAP> email type: </TH> <TD COLSPAN=2> <SELECT CLASS=frmInput ID=lstEmailType NAME="#dsoEmail_emailTypeID" SIZE=1> </SELECT> </TD> </TR> <TR> <TH ALIGN=left NOWRAP> email address: </TH> <TD COLSPAN=2> <INPUT CLASS=frmInput ID=txtEmailAddress NAME="#dsoEmail_emailAddress" TYPE=text MAXLENGTH=255 SIZE=32 onBlur="jsIsEmailValid(this)"> </TD> </TR> <TR> <TH ALIGN=left> url: </TH> <TD COLSPAN=2> <INPUT CLASS=frmInput ID=txtURL NAME="#dsoEmail_url" TYPE=text MAXLENGTH=512 SIZE=48> </TD> </TR> <TR> <TH ALIGN=left> first: </TH> <TD> <INPUT CLASS=frmInput ID=txtFirst NAME="#dsoEmail_first" TYPE=text MAXLENGTH=32 SIZE=32> </TD> <TD ALIGN=right ROWSPAN=2 NOWRAP VALIGN=middle> <STRONG>tagged?:</STRONG> <INPUT ID=chkTagged NAME="#dsoEmail_tagged" TYPE=checkbox> <BR> <STRONG>send?:</STRONG> <INPUT ID=chkSend NAME="#dsoEmail_send" TYPE=checkbox> </TD> </TR> <TR> <TH ALIGN=left> last: </TH> <TD> <INPUT CLASS=frmInput ID=txtLast NAME="#dsoEmail_last" TYPE=text MAXLENGTH=32 SIZE=32> </TD> </TR> <TR> <TD COLSPAN=3> <STRONG>note:</STRONG> <BR> <TEXTAREA CLASS=frmInput ID=txtNote NAME="#dsoEmail_note" ROWS=7 COLS=54></TEXTAREA> </TD> </TR> <TR> <!-- Record filtering: --> <TD COLSPAN=3> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR> <TD VALIGN=middle> <SELECT CLASS=frmCtrl ID=lstFilter NAME=lstFilter SIZE=1 onChange="jsFilter('onchange',dsoEmail)"> <OPTION VALUE="#default" SELECTED>filtering commands</OPTION> </SELECT> <INPUT CLASS=frmCtrl ID=txtFilter NAME=txtFilter TYPE=text MAXLENGTH=32 SIZE=16> <INPUT CLASS=frmCtrl ID=cmdFilter NAME=cmdFilter TYPE=button VALUE="filter on" TITLE="Filter Records" onClick="jsFilter('onclick',dsoEmail)"> </TD> <TD ALIGN=right> <!-- Record navigation: --> <INPUT CLASS=frmCtrl ID=cmdNavFirst NAME=cmdNavFirst TYPE=button VALUE="<<" TITLE="Move to the First Record" onClick="jsDSONav(this.name,dsoEmail)"> <INPUT CLASS=frmCtrl ID=cmdNavPrev NAME=cmdNavPrev TYPE=button VALUE="< " TITLE="Move to the Previous Record" onClick="jsDSONav(this.name,dsoEmail)"> <INPUT CLASS=frmCtrl ID=cmdNavNext NAME=cmdNavNext TYPE=BUTTON VALUE=" > " TITLE="Move to the Next Record" onClick="jsDSONav(this.name,dsoEmail)"> <INPUT CLASS=frmCtrl ID=cmdNavLast NAME=cmdNavLast TYPE=BUTTON VALUE=">>" TITLE="Move to the Last Record" onClick="jsDSONav(this.name,dsoEmail)"> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD COLSPAN=3> <!-- Record commands: --> <BR> <INPUT CLASS=frmCtrl ID=cmdAdd NAME=cmdAdd TYPE=button VALUE="add record" TITLE="Add a New Record" onClick="jsDSOAdd(dsoEmail)"> <INPUT CLASS=cmdDelete ID=cmdDelete NAME=cmdDelete TYPE=button VALUE="delete record" TITLE="Delete the Current Record" onClick="jsDSODelete(dsoEmail)"> <INPUT CLASS=frmCtrl ID=cmdSave NAME=cmdSave TYPE=button VALUE="save changes" TITLE="Save Changes to Records" onClick="jsDSOSave(dsoEmail)"> <INPUT ID=chkRefresh NAME=chkRefresh TYPE=checkbox TITLE="Check to Save Changes to Records on Server?"><STRONG>refresh?</STRONG> </TD> </TR> <TR> <TD COLSPAN=3> <!-- Status reports: --> <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR> <TD CLASS=frmMsg ID=tdMsg> </TD> </TR> </TABLE> </TD> </TR> </TABLE> </BODY> </HTML>
Now the JScript code:
//ADO variables: var vBookMark = null
//---- EditModeEnum Values ---- var adEditNone = 0x0000 var adEditInProgress = 0x0001 var adEditAdd = 0x0002 var adEditDelete = 0x0004
//---- FilterGroupEnum Values ---- var adFilterNone = 0 var adFilterPendingRecords = 1 var adFilterAffectedRecords = 2 var adFilterFetchedRecords = 3 var adFilterPredicate = 4 var adFilterConflictingRecords = 5
//RDS variables: //---- RDS.ADCReadyStateEnum Values ---- var adcReadyStateLoaded = 2 var adcReadyStateInteractive = 3 var adcReadyStateComplete = 4
function jsBindData() { //This function tries very hard to be generic in the Microsoft sense of the word. //It depends on element ID and NAME properties to be different, //where NAME is of the form <data source>_<data field>.
var vCollection = document.all.tags("INPUT")
if (vCollection != null) {
for (var i = 0; i < vCollection.length; i++) {
with(vCollection[i]) {
var vStr = name
if (vStr.indexOf("_") != -1) {
var vArray = vStr.split("_")
if((type == "text") && (readOnly != true)) style.background = "#C0C0C0 none no-repeat scroll 0% 0%"
if((type != "button")
&& (type != "file")
&& (type != "image")
&& (type != "reset")
&& (type != "submit")) {
dataSrc = vArray[0]
dataFld = vArray[1]
}
}
}
}
}
vCollection = document.all.tags("SELECT")
if (vCollection != null) {
for (i = 0; i < vCollection.length; i++) {
with(vCollection[i]) {
vStr = name
if (vStr.indexOf("_") != -1) {
vArray = vStr.split("_")
style.background = "#C0C0C0 none no-repeat scroll 0% 0%"
dataSrc = vArray[0]
dataFld = vArray[1]
}
}
}
}
vCollection = document.all.tags("TEXTAREA")
if (vCollection != null) {
for (i = 0; i < vCollection.length; i++) {
with(vCollection[i]) {
vStr = name
if (vStr.indexOf("_") != -1) {
vArray = vStr.split("_")
if(readOnly != true) style.background = "#C0C0C0 none no-repeat scroll 0% 0%"
dataSrc = vArray[0]
dataFld = vArray[1]
}
}
}
}
}
function jsBindSELECT(vDSOrs,vSELECT){ with(vDSOrs){ while(EOF != true){ vOPTION = document.createElement("OPTION") vOPTION.value = vDSOrs.fields(0) vOPTION.text = vDSOrs.fields(1) vSELECT.add(vOPTION) MoveNext() } MoveFirst() } }
function jsDSOAdd(vDSO) { vDSO.recordset.AddNew() }
function jsDSODelete(vDSO) { if(window.confirm("Are you sure you want to delete this record?") == false) return if (vDSO.recordset.recordCount > 0) vDSO.recordset.Delete() }
function jsDSONav(vCmd,vDSO) {
if(vDSO.recordset.recordcount == 0) {
window.alert("There are no records to display.")
return
}
switch(vCmd){
case "cmdNavFirst":
vDSO.recordset.MoveFirst()
top.status = window.defaultStatus
break
case "cmdNavPrev":
vDSO.recordset.MovePrevious()
top.status = window.defaultStatus
if (vDSO.recordset.BOF) {
vDSO.recordset.MoveFirst()
top.status = "At beginning of records."
}
break
case "cmdNavNext":
vDSO.recordset.MoveNext()
top.status = window.defaultStatus
if (vDSO.recordset.EOF) {
vDSO.recordset.MoveLast()
top.status = "At end of records."
}
break
case "cmdNavLast":
vDSO.recordset.MoveLast()
top.status = window.defaultStatus
break
}
}
function jsDSOSave(vDSO) { with(vDSO) { vBookMark = vDSO.recordset.bookmark SubmitChanges() if(chkRefresh.checked) Refresh() }
}