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

onChage displays corresponding items in checkboxes problem.. 1

Status
Not open for further replies.

necta

Technical User
Mar 8, 2004
35
MY
I have a drop down selection (<option>T1</option>...)menu, when onChange, a list of checkboxes items will b displayed according to the option selected below the option menu. How would I do that? I wonder VBSCript will be able to perform the duty.
Thank you.
 
In the OnChange you'll typically submit the form.
In the <FORM> tag of the page you define where to. I presume your user may 'play' with the <SELECT> options, and each time other/new (?) checkboxes must appear. So it will be wise to re-enter the same page.
Your page should check if a value for that <SELECT> is known (so you can highlight the correct OPTION), and based on that value you can paint the rest of the screen...

this shows 1 way to do it: (save it as form1.asp)

Code:
<%
' we need a little UDF in order to write the word 
' "selected" in the correct option
function Selected(x,y)
 if Cint(x) = Cint(y) then Selected =" selected "
end function

' get the selected option from the previous form
dim cOption
cOption = Request.Form("fSelect")
%>
<form action=form1.asp method=post>
<select name=fSelect OnChange="submit();">
<%
for i = 1 to 3
  Response.Write "<option " & i &_
           Selected(i, cOption) &_
           " value=" & i & ">T" & i
next 
%>
</select>
</form>

<form action=form2.asp method=post>
<%
' based on the selected option put 1...3 checkboxes 
' on screen
if cOption <> "" then
 for i = 1 to Cint(cOption)
  Response.Write "<input type=checkbox name=fCheck" &_
                  i & "><br>"
 next
 Response.Write "<br><input type=submit>"
end if
%>
</form>




ttmug.gif
 
Thanks for the reply, I tried to apply in my code but it did not work. I intend to submit the radio button value, the option value and the checkbox value at once. The value from the option menu did not go to the checkbox. I wonder what could be wrong.

.....
<!--Input type for entering subject ID and subject name-->

<form name="form1" ID="frm1" method="post" action="onchange.asp">
<input type="hidden" name"frmSubj" value="<%formOption)%>

<!--Class radio button-->
<table align=center border=1>

<tr>
<td>
<% If Not clsRS.EOF Then
clsRS.MoveFirst %>

<!-- Continue until we get to the end of the recordset.-->
<% Do While Not clsRS.EOF%>

<input type="radio" name='class' value="<%=clsRS("clsID")%>">
<%=clsRS("clsID")%>

<%'Get next record
clsRS.MoveNext
Loop
End if %>

</td>
</tr>
</table>

<!--Select Option-->
<table align=center border=1>
<tr>
<td colspan=2>
<%
If Not frmRS.EOF Then
frmRS.MoveFirst
%>
<select name="frmOption" OnChange="submit();">
<%
' Continue until we get to the end of the recordset.
Do While Not frmRS.EOF
%>
<!--
<input type="radio" name='form' value="<%=frmRS("frmID")%>-->
<%'=frmRS("frmID")%>
%>

<option value="<%=frmRS("frmID")%>">
<%=frmRS("frmID")%></option>
<%
'Get next record
frmRS.MoveNext
Loop
%>
</select>
</TD>
</TR>

<!--form action=form2.asp method=post-->
<%
sOption=Request.form("formOption")
Set subjRS=Server.CreateObject("ADODB.Recordset")
sql="SELECT subjID FROM TblForm_Subj WHERE frmID='"&sOption&"'"
Set subjRS=wCON.Execute(sql)

If sOption <>"" then

'Response.Write(sql)
If Not subjRS.EOF Then
subjRS.MoveFirst %>

<!-- Continue until to the end of the recordset.-->
<% Do While Not subjRS.EOF%>

<input type="checkbox" name='subject' value="<%=subjRS("subjID")%>">
<%=subjRS("subjID")%>

<%'Get next record
subjRS.MoveNext
Loop
Response.Write"<input type=submit>"
End if
End If%>

<%
'subjRS.Close
'Set subjRS=nothing %>
<%
'--Close all connection
clsRS.Close
Set clsRS = Nothing
wCON.Close
Set wCON = Nothing
End If
%>

<tr>
<td align=right><INPUT TYPE="submit" VALUE="Send" ID=submit1 NAME=submit1></td>
<td><INPUT TYPE="reset" VALUE="Reset" ID=reset1 NAME=reset1></td>
</tr>
</table>
</form>
</body>
</html>
 
1. type error
Code:
change:

<input type="hidden" name"frmSubj" value="<%formOption)%>

into

<input type="hidden" name"frmSubj" value="<%= formOption %>


2. error in variable name
Code:
sOption=Request.form("formOption")

will not work because the SELECT is called frmOption:

<select name="frmOption" OnChange="submit();">







ttmug.gif
 
Thanks, that's really help. It works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top