Link to home
Start Free TrialLog in
Avatar of deross
deross

asked on

select box using java & vbscript

What is wrong with this code?

<%
dim tconn, tcstr, tsql, trs
set tconn = server.createobject("adodb.connection")
tconn.open("driver={microsoft access driver (*.mdb)}; dbq=d:\webspace\fw1\cc01\ccom.ca\db\ccom_atms.mdb")
tsql = "select TermID from TerminalID order by TermID"
set trs = tconn.execute(tsql)
%>
<script language="javascript" type="text/javascript">
var x = 0
document.mform.tchoice.options[x] = new option("Select A Terminal","2");
</script>
<%
do while not trs.eof
%>
<script language="javascript" type="text/javascript">
x = x + 1
document.mform.tchoice.options[x] = new option("<% =trs("TermID") %>","<% =trs("TermID") %>");
</script>
<%
trs.movenext
loop
trs.close
tconn.close
set trs = nothing
set tconn = nothing
%>
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of findajay
findajay

Hey Friend,

If you want your code to work, simply put your code at the end of page. Or put it in a java script function and call in on OnLoad event of the body.

It is very important that the select box tag is defined before ur script tag.

Enjoy!!!
Avatar of deross

ASKER

I already have a select box.  This procedure is called when the user clicks one of two radio buttons (sort ascending or descening).  After the user clicks a radio button, the existing select box clears and re-populates.  If I put a select box tag, I get a brand new select box.
You want to make the select in the client or server? The code you have shown is server side. Since you are already on the server there is no point in writing javascript code. If you wanted all this to happen without server call, then it needs to be totally in client side javascript.
Avatar of deross

ASKER

I think the whole thing needs a new approach.  All I want to do is:

Have a select box populated with records from an access database.

If the user clicks one of two radio buttons the select box should clear and be re-populated with the records from that same database but sorted by a different field.