<script language = "VBscript" runat = "Server"> function dbug(ss) Response.Clear() Response.Write(ss) Response.End() end function '--dbug </script> <script language = jscript runat = server> /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-- * FUNCTION: fnDataRADIO(...) * DESCRIPTION Display a data bound set of RADIO butttons * STATUS: partially working, not tested (april 26, 2000) * DEPENDENCIES: fnCheckForField(), fnErrorMessage() * WORKING HISTORY: 27th Nov 2000-- tidied * LOCATION: h:\LibraryCode\JavaScript\AspFunctions\SourceCode1\ * DOCUMENTED AT: h:\LibraryCode\JavaScript\AspFunctions\ * TO DO: a) Add a non-specific SQL SVR 7 parameter b) Combine the aaConnect and adoConnection parameters c) double quotes problem. d) layout columns parameter e) *--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnDataRADIO( adoConnection, sLookupString, sValueField, sDisplayField, sSelectedValue, sName, aaConnect) { var bCloseConnection = new Boolean(false); var sConnString = new String(); var sQuery = new String(); var adoRs; //' on error resume next if (sSelectedValue == null) {sSelectedValue = '0';} if (sLookupString == null) { fnErrorMessage( "fnDataSELECT", "LookupString", "This required parameter was omitted from the function call."); } /* if parameters missing */ if ((adoConnection == null) && (aaConnect == null)) { fnErrorMessage( "fnDataSELECT", "adoConnection, aaConnect", "One of the two parameters above must be supplied<br>" + "Both were omitted."); } /* if no db opening info */ if ((adoConnection == null) && (aaConnect != null)) { var sConn; //temp string variable var aaCon = new Array(); aaConn = fnConvertArray(aaConnect); //***Provide some default values if (aaConn[0] == null) {aaConn[0] = "sql server";} if (aaConn[1] == null) {aaConn[1] = "(local)";} if (aaConn[2] == null) {aaConn[2] = "sa";} if (aaConn[3] == null) {aaConn[3] = "max";} sConn = "DRIVER={" + aaConn[0] + "};"; sConn += "SERVER=" + aaConn[1]; adoConnection = Server.CreateObject("ADODB.connection"); //dbug(sConn); adoConnection.Open(sConn, aaConn[2], aaConn[3]); if (aaConn[4] != null) {adoConnection.DefaultDatabase = aaConn[4];} /* try, catch */ bCloseConnection = true; } /* if no connection */ adoRs = Server.CreateObject("ADODB.recordset"); adoRs.ActiveConnection = adoConnection; //***different types of open strings var regP = /\bselect\b/gi; var sQ; if (regP.test(sLookupString) == false) { //***handle raw table names var sQ = "sp_tables '" + sLookupString + "'"; //dbug(sQ); adoRs.Open(sQ); if (!adoRs.EOF) { sLookupString = "SELECT * FROM " + sLookupString; } /* if */ else { //***handle stored procedures var regQ = /([\w]+) (.)/gi; sLookupString = sLookupString.replace(regQ, "$1"); adoRs.Close(); dbug(sLookupString); var sQ = "sp_stored_procedures '" + sLookupString + "'"; adoRs.Open(sQ); if (!adoRs.EOF) { sLookupString = sLookupString; } /* if */ else { fnErrorMessage( "fnDataSELECT", "sLookupString ('" + sLookupString + "')", "The parameter is neither a SQL SELECT statement,<br>" + "nor the name of a Table, nor the name of a stored procedure<br>" + "in the database. The parameter must be one of these"); } /* if, else */ } /* if, else */ adoRs.Close(); } /* if */ adoRs.MaxRecords = 1000; adoRs.Open(sLookupString); /* try, catch */ if (adoRs.EOF) {sReturn = "ERROR:"} if (!adoRs.EOF) { //***Defaults and error checking if (sValueField == null) { sValueField = adoRs.Fields.Item(0).Name; } /* if */ if (sDisplayField == null) { sDisplayField = adoRs.Fields.Item(1).Name; } /* if */ if (fnCheckForField(adoRs, sValueField) == false) { fnErrorMessage( "fnDataSELECT", "sValueField ('" + sValueField + "')", "The parameter does not correspond to any field<br>" + "in the data set"); } /* if */ if (fnCheckForField(adoRs, sDisplayField) == false) { fnErrorMessage( "fnDataSELECT", "sDisplayField ('" + sDisplayField + "')", "The parameter does not correspond to any field<br>" + "in the data set"); } /* if */ } /* if there is data */ /* strReturn = "<table><tr>"; while (!rsLookup.EOF) { n = n + 1; strReturn += "<td><input type = radio name = " + strName; strReturn += " value = " + rsLookup(sValueField); if (rsLookup(sValueField) == parseInt(SelectedValue)) {strReturn += " CHECKED";} strReturn += ">" + rsLookup(sDisplayField) + "</td>"; if ((n% parseInt(LayoutColumns)) == 0) {strReturn += "</tr><tr>";} rsLookup.MoveNext(); } strReturn += "</tr></table>"; */ var n = 0; strReturn = "<table><tr>"; //*** create the option elements while (!adoRs.EOF) { n++; strReturn += "<td><input type = radio name = " + sName; strReturn += " value = \"" + Server.HTMLEncode(adoRs(sValueField)) + "\" "; if (adoRs(sValueField) == sSelectedValue) {strReturn += " CHECKED";} strReturn += ">" + Server.HTMLEncode(adoRs(sDisplayField)) + " </td>\n"; if ((n% parseInt("3")) == 0) {strReturn += "</tr><tr>";} adoRs.MoveNext(); } /* while */ strReturn += "</tr></table>\n"; strReturn += "<input type = 'hidden' name = 'hidValueField' \n" + " value = \"" + sValueField + "\">\n"; strReturn += "<input type = 'hidden' name = 'hidDisplayField' \n" + " value = \"" + sDisplayField + "\">\n"; strReturn += "<input type = 'hidden' name = 'hidOriginalValue' \n" + " value = \"" + sSelectedValue + "\">\n"; adoRs.Close(); adoRs = null; if (bCloseConnection == true) { adoConnection.Close(); adoConnection = null; } /* if */ return strReturn; } /* fndataRADIO */ </script>