I have a question.I am working on a Classic ASP website.
So this question is related to VBSCRIPT and JavaScript and sql server.
I have a database table [test_table].On the website there are 2 comboboxes : ComboBox 1 and ComboBox 2.
When the page is shown ,
I will populate my ComboBox 1 with data from [test_table] Setting the ComboBox 1 value with t00_test_cd and text with (t00_test_cd : t00_test_name ) format. If there is No data or records in 「test_table」ComboBox 1 ‘s value is “” and text is blankspace.
ComboBox 2 is populated with the following value and text (value:0 is selected)
「value : 0 , text : text0」
「value : 1 , text : text1」
「value : 2 , text : text2」
When I change the ComboBox 1 value which is t00_test_cd , ComboBox 2 is Disabled or Enabled Base on t00_combo2_display.
(t00_combo2_display → 0:comboBox 2 disabled and comboBox 2 value should be set with t00_combo2_val)
(t00_combo2_display → 1:comboBox 2 enable and comboBox 2 is selected with value 0 and text text0 and user can choose the comboBox 2 value)
「test_table」
t00_timestamp | t00_test_cd | t00_test_name | t00_combo2_display | t00_combo2_val |
---|---|---|---|---|
2024-08-31 11:57:41.773 | 01 | test_01 | 0 | 0 |
2024-08-31 11:57:41.773 | 02 | test_02 | 1 | 2 |
Explanation of 「test_table」values
t00_test_cd → populate the Combo Box 1’s value (and text)
t00_test_name → populate the Combo Box 1’s text (t00_test_cd : t00_test_name) for example, (01 : test_01)
t00_combo2_display → 0 is Combo Box 2 disabled and Combo Box 2 value will be t00_combo2_val.
→ 1 is Combo Box 2 enable and user can choose Combo Box 2 value of「value : 0 , text : text0」 「value : 1 , text : text1」 「value : 2 , text : text2」
t00_combo2_val → when t00_combo2_display is 0 , Combo Box 2 value is set with t00_combo2_val.t00_combo2_val can be 「0」「1」「2」.
I have tried to query Combo Box 1 value from test_table and populate the Combo Box 2 value with default「0,1,2」.After that, i don’t know what to do Next.
Code Below
<% @LANGUAGE="VBSCRIPT" %>
<%Option Explicit%><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Shift_JIS">
<HTML>
</HTML>
<!--#INCLUDE VIRTUAL="/scripts/db/database.asp"-->
<%
Dim DBC,DBC1
Dim RS,RS1
Dim cmd
Dim t00_test_cd
Dim t00_test_name
Dim t00_combo2_display
Dim t00_combo2_val
Call Set_Value
%>
<html>
<body>
<h1>This Is Test Page</h1>
<br>
<h6>
I Want to query from「test_table」and populate the Combo Box 1 with t00_test_cd value(Defalut value is "" and text is blankspace) and Combo Box 2 with (value:0, text0) , (value:1, text1),(value:2, text2)
when the t00_combo2_display is 「0」Combo Box 2 is disabled and value and text will be (value:t00_combo2_val, text0) and user cannot change the Combo Box 2.
when the t00_combo2_display is 「1」Combo Box 2 is enabled and value and text will be (value:0, text0) and user can change the Combo Box 2 value with (value:0, text0) , (value:1, text1),(value:2, text2) .
</h6>
<br>
<TABLE BORDER="0" BGCOLOR="#33d4ff" WIDTH="50%" CELLSPACING="1" CELLPADDING="1">
<TR VALIGN="MIDDLE">
<TH NOWRAP ALIGN="left" COLSPAN="8" class="auto-style1"> <FONT COLOR="Red">COMBO BOX 1 :</FONT> </TH>
<TD NOWRAP ALIGN="center" class="auto-style1"></TD>
</TR>
<TR VALIGN="MIDDLE">
<TD NOWRAP ALIGN="RIGHT" WIDTH="5%">
</TD>
<TD NOWRAP ALIGN="LEFT" COLSPAN="7">
<SELECT NAME="m49_provider_cd" onchange="ComboChange(providerClsDic)">
<OPTION VALUE=""></OPTION>
<%Set DBC1 = ConnectDB("","","","")
Set RS1 = Server.CreateObject("ADODB.RecordSet")
RS1.CursorLocation = conCursorLocation
RS1.Open "SELECT * FROM test_table with(nolock) order by t00_test_cd",DBC1,conCursorType,conLockType,conCommandType
Set RS1.ActiveConnection = Nothing
If RS1.EOF<>True Then
Do While true%>
<OPTION VALUE="<%=RS1.Fields("t00_test_cd")%>"<%If trim(RS1.Fields("t00_test_cd"))=trim(t00_test_cd) Then Response.Write " SELECTED" End If%>><%="(" & RS1.Fields("t00_test_cd") & ")" & RS1.Fields("t00_test_cd")%></OPTION>
<%RS1.MoveNext
If RS1.EOF Then Exit Do
Loop
End If
RS1.Close
Set RS1 = Nothing
Call DisConnectDB(DBC1)%>
</SELECT>
</TD>
<TD NOWRAP ALIGN="center"> </TD>
</TR>
<TR>
<TD NOWRAP ALIGN="center"> </TD>
</TR>
<TR VALIGN="middle">
<TD NOWRAP ALIGN="right" WIDTH="1%">
<FONT COLOR="Red"> COMBO BOX 2 :</FONT>
</TD>
<TD NOWRAP ALIGN="left" COLSPAN="7">
<SELECT NAME="t00_combo2_val">
<OPTION VALUE=""
<% If trim(t00_combo2_val) = "0" Then Response.Write " SELECTED" End If %> >text0</OPTION>
<OPTION VALUE="1"
<% If trim(t00_combo2_val) = "1" Then Response.Write " SELECTED" End If %> >text1</OPTION>
<OPTION VALUE="2"
<% If trim(t00_combo2_val) = "2" Then Response.Write " SELECTED" End If %> >text2</OPTION>
</SELECT>
</TD>
<TD NOWRAP ALIGN="center"> </TD>
</TR>
</Table>
</body>
</html>
<%
Sub Set_Value()
t00_test_cd = ""
t00_test_name = ""
t00_combo2_display = ""
t00_combo2_val = ""
End Sub
%>