Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic list selections and my faulty FillArray.

Status
Not open for further replies.

rotschreck

Programmer
Jan 26, 2000
54
0
0
CA
www.geocities.com
Hey there.<br><br>I am working on trying to get some combo boxes to select a selection list in another selction list. So far the code seems to be ok except that it doesn't work. ... so obviously I missed something.<br><br>As far as I can see, it has something to do with the FillArray command on line 39, as after that line, nothing prints to the screen.<br><br>Here's the code and thanks in advance for any help you can offer:<br><br>____________________________________________________________<br>&lt;%@ Language=VBScript %&gt;<br>&lt;% Option Explicit %&gt;<br><br>&lt;!-- #include file=adovbs.inc --&gt;<br>&lt;!-- #include file=DynamicSelect.inc --&gt;<br><br>&lt;%<br>DIM Conn, rsPrimary, rsSecondary, intFirstPub, DB_CONNECTIONSTRING, objRecordset <br><br>&nbsp;' Put your connection information here.<br>&nbsp;'Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)<br><br>DB_CONNECTIONSTRING = &quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=&quot; & Server.Mappath(&quot;mndm.mdb&quot;) & &quot;;&quot;<br>Conn = &quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=&quot; & Server.Mappath(&quot;mndm.mdb&quot;) & &quot;;&quot;<br><br>&nbsp;SET rsPrimary = Server.CreateObject(&quot;ADODB.RecordSet&quot;)<br>&nbsp;SET rsSecondary = Server.CreateObject(&quot;ADODB.RecordSet&quot;)<br>&nbsp;Set objRecordset = Server.CreateObject(&quot;ADODB.Recordset&quot;)<br>%&gt;<br><br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&lt;TITLE&gt;Help<br>&lt;/TITLE&gt;&lt;/HEAD&gt;<br><br>&lt;BODY&gt;<br><br>&lt;%<br>objRecordset.Open &quot;withdrawalsReopenings&quot;, DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable<br>rsPrimary.Open &quot;SELECT primid, primpurp FROM purpose1 ORDER BY primpurp&quot;, Conn<br><br>IF NOT (rsPrimary.BOF AND rsPrimary.EOF) THEN<br>&nbsp;&nbsp;&nbsp;intFirstPub = rsPrimary(&quot;primid&quot;)<br>ELSE<br>&nbsp;&nbsp;&nbsp;intFirstPub = 0<br>END IF<br>rsSecondary.Open &quot;SELECT primid, secid, secpurp FROM purpose2 ORDER BY primid, secpurp&quot;, Conn <br><br>FillArray &quot;arrpurpose2&quot;, rsSecondary, &quot;primid&quot;, &quot;secid&quot;, &quot;secpurp&quot;<br>%&gt;<br><br>&lt;CENTER&gt;<br>&lt;H2&gt;Dynamic Select List&lt;/H2&gt;<br>&lt;FORM&gt;<br>&lt;TABLE WIDTH=100%&gt;<br>&lt;TR&gt;<br>&nbsp;&lt;TD&gt;Primary List:&lt;br&gt;<br>&lt;%SelectBox rsPrimary, &quot;lstpurpose1&quot;, &quot;primid&quot;, &quot;primpurp&quot;, &quot;lstpurpose2&quot;, &quot;arrpurpose2&quot; %&gt;<br>&nbsp;&lt;/TD&gt;<br>&nbsp;&lt;TD&gt;Secondary List:&lt;br&gt;<br>&lt;%<br>&nbsp;&nbsp;&nbsp;rsSecondary.Filter = &quot;primid = '&quot; & intFirstPub & &quot;'&quot;<br>&nbsp;&nbsp;&nbsp;SelectBox rsSecondary, &quot;lstpurpose2&quot;, &quot;secid&quot;, &quot;secpurp&quot;, &quot;&quot;, &quot; &quot; <br>&nbsp;&nbsp;&nbsp;rsSecondary.Filter = adFilterNone<br>%&gt;<br>&nbsp;&lt;/TD&gt;<br>&lt;/TR&gt;<br>&lt;/TABLE&gt;<br>&lt;/FORM&gt;<br>&lt;/CENTER&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt; <p> <br><a href=mailto: > </a><br><a href= Eclectic Page</a><br>
 
Dear Rotschrck,<br><br>Where is the definition of 'FillArray'?<br><br>Also what is this line supposed to do:<br>&gt;&lt;%SelectBox rsPrimary, &quot;lstpurpose1&quot;, &quot;primid&quot;, &quot;primpurp&quot;, &quot;lstpurpose2&quot;, &quot;arrpurpose2&quot; %&gt;<br><br>If 'SelectBox' is a VBScript function that returns a string that you want inserted into the HTML document at that position, then you need to have an equal sign in front of it i.e.:<br><br>&lt;%=SelectBox ....%&gt;<br><br>Also if in VBScript if 'SelectBox' is a function don't you need to enclose the parameter list in parentheses for proper syntax?<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete
 
Sorry, I forgot to include the DynamicSelection.inc file. Fillarray and Selectbox are in there.<br>____________________________________________________________<br><br>&lt;SCRIPT RUNAT=&quot;server&quot; LANGUAGE=&quot;VBScript&quot;&gt;<br><br>SUB SelectBox(rsOptions, strName, strValue, strDisplay, strSecondary, strArray)<br><br>'Creates a Select box from a recordset<br>'rsOptions the recordset which provides the data to display;<br>'strName the name we assign to the list within the HTML form;<br>'strValue the field for the value to be passed when the form is submitted;<br>'strDisplay the field to be displayed for each option in the list;<br>'strSecondary the Select list that will change in response to changes in <br>' the list being created here;<br>'strArray the array that will populate the list identified by strSecondary.<br><br>&nbsp;&nbsp;&nbsp;Response.Write vbCRLF & &quot;&lt;SELECT name=&quot; & chr(34) & strName & chr(34) & _<br>&nbsp;&nbsp;&nbsp;&quot; id=&quot; & chr(34) & strName & chr(34) & _<br>&nbsp;&nbsp;&nbsp;&quot; size=1 onChange=&quot; & chr(34) & &quot;ChangeOptions('&quot; & _<br>&nbsp;&nbsp;&nbsp;strName & &quot;', '&quot; & strSecondary & &quot;', '&quot; & strArray & &quot;')&quot; & chr(34) & &quot;&gt;&quot; & vbCRLF<br><br>&nbsp;&nbsp;&nbsp;Do Until rsOptions.EOF<br>&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;OPTION value=&quot; & chr(34) & rsOptions.Fields(strValue) & chr(34) & &quot;&gt;&quot;<br>&nbsp;&nbsp;&nbsp;Response.Write Trim(rsOptions.Fields(strDisplay)) & &quot;&lt;/OPTION&gt;&quot; & vbCRLF<br>&nbsp;&nbsp;&nbsp;rsOptions.MoveNext<br>LOOP<br><br>Response.Write &quot;&lt;/SELECT&gt;&quot;<br>END SUB<br><br>SUB FillArray(strArrName, rsSource, strKey, strValue, strDisplay)<br><br>'Populate arrOptions as a two dimensional array.<br>'strArrName, the name we give the array;<br>'rsSource, the recordset used to populate the array;<br>'strKey, the name of the recordset field that will provide the &quot;key&quot; values<br>' in the list’s options;<br>'strValue, the name of the recordset field that will provide the option<br>' values submitted as part of the HTML form;<br>'strDisplay, the name of the recordset field that will provide the display 'values in the list’s options.<br>'<br>'[n][0] =matches the selected key from the primary list; <br>'[n][1] =option value;<br>'[n][2] =display <br><br>Response.Write &quot;&lt;SC&quot; & &quot;RIPT LANGUAGE= &quot;&quot;JavaScript&quot;&quot;&gt;&quot; & _<br>&quot;var &quot; & strArrName & &quot; = new Array(); &quot; & vbCRLF<br>DIM intRow<br>intRow = 0<br>DO UNTIL rsSource.EOF<br>&nbsp;&nbsp;&nbsp;Response.Write strArrName & &quot;[&quot; & CStr(intRow) & _<br>&nbsp;&nbsp;&nbsp;&quot;] = new Array ('&quot; & _<br>&nbsp;&nbsp;&nbsp;SingleQuote(Trim(rsSource (strKey))) & _<br>&nbsp;&nbsp;&nbsp;&quot;', '&quot; & rsSource(strValue) & _<br>&nbsp;&nbsp;&nbsp;&quot;', '&quot; & SingleQuote(Trim(rsSource(strDisplay))) & _<br>&nbsp;&nbsp;&nbsp;&quot;');&quot; & vbCRLF<br>&nbsp;&nbsp;&nbsp;intRow = intRow + 1<br>&nbsp;&nbsp;&nbsp;rsSource.MoveNext<br>&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;&nbsp;Response.Write &quot; &lt;/SC&quot; & &quot;RIPT&gt;&quot;<br>END SUB<br><br>Response.Write strArrName & &quot;[&quot; & CStr(intRow) & _<br>&nbsp;&nbsp;&nbsp;&quot;] = new Array ('&quot; & _<br>&nbsp;&nbsp;&nbsp;SingleQuote(Trim(rsSource (strKey))) & _<br>&nbsp;&nbsp;&nbsp;&quot;', '&quot; & rsSource(strValue) & _<br>&nbsp;&nbsp;&nbsp;&quot;', '&quot; & SingleQuote(Trim(rsSource(strDisplay))) & _<br>&nbsp;&nbsp;&nbsp;&quot;');&quot; & vbCRLF<br><br>FUNCTION SingleQuote(strTarget)<br>&nbsp;&nbsp;&nbsp;'&quot;Escapes&quot; embedded single quote in a text string.<br>&nbsp;&nbsp;&nbsp;intPos = InStr(1, strTarget, &quot;'&quot;)<br>&nbsp;&nbsp;&nbsp;DO WHILE intPos &gt; 0 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strTarget = Left(strTarget, intPos - 1) & &quot;\'&quot; & _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Right(strTarget, Len(strTarget) - intPos)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Bump up TWO places because the original single quote has moved.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intPos = InStr(intPos + 2, strTarget, &quot;'&quot;)<br>&nbsp;&nbsp;&nbsp;LOOP<br><br>&nbsp;&nbsp;&nbsp;SingleQuote = strTarget<br>END FUNCTION<br>&lt;/script&gt;<br> <p> <br><a href=mailto: > </a><br><a href= Eclectic Page</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top