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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with my code??

Status
Not open for further replies.

ribena

Technical User
Jan 4, 2001
3
HK
I am writing a program for dynamically linked 2 listboxes with VBScript & MS Access. There are contained 2 asp files, one is called newsSearchForm1, another is newsSearchForm2 and my database is NewsData.mdb.

1st file (NewsSearchForm1.asp):

<script language=&quot;JavaScript&quot;>
var serverURL = 'newsSearchForm2.asp';

function myCallBack(co) {
if (co.status != -1) {
eval(co.return_value);
}
}

function GetModels() {
RSExecute(serverURL
,'RSGetModel'
,'document.forms[0].QryStr4'
,document.forms[0].QryStr3.options[document.forms[0].QryStr3.selectedIndex].value
,myCallBack(co));
}
</script>

<form>
<table border=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td>&amp;nbsp;&amp;nbsp;&amp;nbsp;</td>
<td><p align=&quot;right&quot;>Category Code: </p></td>
<td></td>
<td>
<select name=QryStr3 onChange=&quot;GetModels()&quot;>
<option value=&quot;0&quot;>Select Category Code

<%
myconn = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=&quot; &amp; server.mappath(&quot;NewsData.mdb&quot;) &amp; &quot;;&quot;
myquery=&quot;select distinct Category from Category&quot;
dim conntemp, rstemp
set conntemp=server.createobject(&quot;adodb.connection&quot;)
conntemp.open myconn
set rstemp=conntemp.execute(myquery)
do while not rstemp.eof
fieldfirst=RStemp(0)
if isnull(fieldfirst) or fieldfirst=&quot;&quot; then
' ignore
else
response.write &quot;<option value='&quot; &amp; fieldfirst
response.write &quot;'>&quot; &amp; fieldfirst &amp; &quot;</option>&quot;
end if
rstemp.movenext
loop
%>
</select>
<%
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</td>
</tr>
<tr>
<td>&amp;nbsp;&amp;nbsp;&amp;nbsp;</td>
<td><p align=&quot;right&quot;>MICode: </p></td>
<td></td>
<td>
<select name=QryStr4>
<option value=&quot;0&quot;>Select MICode
</td>
</tr>
</form>

2nd file (NewsSearchForm2):

<%RSDispatch%>

<SCRIPT RUNAT=SERVER Language=javascript>

function Description()
{
this.RSGetModel = Function(&quot;lbname&quot;,&quot;Qrystr3&quot;,&quot;return RSGetModels(lbname,QryStr3)&quot;);
}
public_description = new Description();

</SCRIPT>

function RSGetModels(lbname,QryStr3)
dim SQL
SQL=&quot;select MICode from Category where Category = &quot; &amp; QryStr3
RSGetModels=RemoteScriptListBox(lbname,SQL)
end function

function jq(str)
dim ret
ret=str &amp; &quot;&quot;
ret=replace(ret,&quot;\&quot;,&quot;\\&quot;) 'escape any backslashs
ret=replace(ret,&quot;'&quot;,&quot;\'&quot;) 'escape any single quotes
ret=replace(ret,&quot;&quot;&quot;&quot;,&quot;\&quot;&quot;&quot;) 'escape any double quotes
jq=&quot;'&quot; &amp; ret &amp; &quot;'&quot; 'surround with single quotes
end function

function RemoteScriptListBox(lbname,SQL)
dim comma,x,conn,rx,col1,col2
dim ret

set conn=server.CreateObject(&quot;ADODB.Connection&quot;)
myconn = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=&quot; &amp; server.mappath(&quot;NewsData.mdb&quot;) &amp; &quot;;&quot;
conn.open myconn

comma=&quot;&quot;
x=0

ret = ret &amp; &quot;var lb=&quot; &amp; lbname &amp; &quot;;&quot;

'--create remote array
ret = ret &amp; &quot;var _o0=new Array(&quot;
Set rx = conn.Execute(SQL)
do while not rx.eof

col1=cstr(rx(0) &amp; &quot;&quot;)
col2=trim(cstr(rx(1) &amp; &quot;&quot;))

ret = ret &amp; comma &amp; jq(col2) &amp; &quot;,&quot; &amp; jq(col1)
comma=&quot;,&quot;

x=x+1
rx.movenext
loop
rx.close
conn.close
ret = ret &amp; &quot;);&quot;

ret = ret &amp; &quot;lb.length=0;&quot;
ret = ret &amp; &quot;var x=0;&quot;
ret = ret &amp; &quot;while (x != _o0.length) {&quot;
ret = ret &amp; &quot;lb.options[lb.length] = new Option(_o0[x],_o0[x+1]);&quot;
ret = ret &amp; &quot;x=x+2;}&quot;

RemoteScriptListBox = ret
End function
%>

A problem is when I chose the first listbox, there is no response for the second listbox. Can someone tell me what's wrong with my code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top