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

Dynamically load listbox based on radio button selection

Status
Not open for further replies.

JanS

Technical User
Feb 21, 2001
77
AU
I would like to be able to take options users have selected from two groups of radio buttons, compile and run database query and then add the resulting recordset to a listbox.

All of this without refreshing or changing the current form in any way! I am trying to make the form a little bit smart by making the listbox selection relivant to the options the user has selected from the radio buttons.

ie
1. the user selects an option from both group 1 and group 2
2. the listbox automaticlly updates with the relivant options for the combination of items from group 1 and group 2

Is this possible?

I can add a call to a function on the "onclick" event of all radio buttons but as this function is VBScript, I cant connect to the database. How can I query the database without having to load another form or reresh the current one? ie run ASP code to connect to the database and run the query.

Any advice would be appreciated.
jan
 
It is not possible to connect to the database without submitting the form and returning to the server. If you want everything done on the client side, then your only option is to get all the required information from the database when you are loading the form and store this information in client side arrays. Then using the users selections, pull the required data from the arrays and generate your listbox. Mise Le Meas,

Mighty :)
 
What you want can be done (I do it frequently in the app I'm currently working on).

Look into using the Remote Data Services (RDS) feature of ADO.
 
Thanks for your advice. I have been able to add the recordset into an array and load this into the listbox.

But, how do I go about selecting items from this array based on the radio buttons the user selects and regenerate the listbox?

I have placed a call to a function on each radio button. However, I cant see how I can re-populate the listbox from within these functions.

Ive included a sample of what ive got so far.

Further assistance would be greatly appreciated.

jan


<%
....processing here to get the recordset
...assign the dataset to an array
RSArray = RSReport.getrows

%>

<HTML><HEAD><TITLE></TITLE>

<body>
<SCRIPT language=&quot;VBScript&quot;>
sub GetState(obj)
state = obj.value
call GetData(state, null)
end sub

sub GetType(obj)
SType = obj.value
alert(SType)
call GetData(null,SType)
end sub

sub GetData(State, SType)

SOMETHING HERE TO POPULATE THE LISTBOX WITH THE NEW DATA
THE LISTBOX SHOULD NOT BE POPULATED AS IT IS NOW. IT SHOULD BE EMPTY UNTIL THE USER SELECTS THE RADION BUTTONS.

end sub
</SCRIPT>


<FORM METHOD=&quot;post&quot; ACTION=&quot;&quot;>

<P><INPUT name=State type=radio value=ACT onclick=&quot;return GetState(this)&quot;>ACT </P>

<P><INPUT name=Type type=radio value=P onclick=&quot;return GetType(this)&quot;>Primary</P>

<SELECT id=select1 name=code>
<OPTION selected></OPTION> <!--dont select an item-->
<%Number_Of_Fields = Cdbl(ubound(RSArray, 1))
Number_Of_Records = Cdbl(UBound(RSArray, 2))
For R = 0 to Number_Of_Records%>
<OPTION NAME=&quot;Code&quot; VALUE=<%=RSArray(1,R)%>><%=RSArray(1,R)%> - <%=RSArray(0,R)%>
<%Next %>
</SELECT>

<P><INPUT id=submit1 name=submit1 type=submit value=&quot;Submit Query&quot;><INPUT id=reset1 name=reset1 type=reset Value=Reset> </P>
</FORM>

</body>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top