472,956 Members | 2,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,956 software developers and data experts.

Problem with dependant drop down

PT
I got a form with many text boxes, checkboxes and 3 drop downs. From
that 3, 2 are dependant. I can choose one drop down, and the next drop
down should display the dependant values of the first drop down
chosed. And I have a submite button to submit all these values to DB.

First problem: I cant keep the value of the selected text in the first
drop down. It always goes back to the first value. (but the asp site
extension changes accordingly).

Second problem: when the value of second drop down is updated, then
the text I inserted in those text boxes, and the checkboxes i checked
disappears!

I know its because the site is submitted again to update the second
drop down. But how could I keep the values of other elements even
though the drop down is updated?

Thank you. I'll post the code too, if anyone wants to look at it. (but
its a big one!!)
Jul 19 '05 #1
6 2417
I thought you better provides the source to us then we can know it in depth
Jul 19 '05 #2
PT wrote:
I got a form with many text boxes, checkboxes and 3 drop downs. From
that 3, 2 are dependant. I can choose one drop down, and the next drop
down should display the dependant values of the first drop down
chosed. And I have a submite button to submit all these values to DB.

First problem: I cant keep the value of the selected text in the first
drop down. It always goes back to the first value. (but the asp site
extension changes accordingly).

Second problem: when the value of second drop down is updated, then
the text I inserted in those text boxes, and the checkboxes i checked
disappears!

I know its because the site is submitted again to update the second
drop down. But how could I keep the values of other elements even
though the drop down is updated?

Thank you. I'll post the code too, if anyone wants to look at it. (but
its a big one!!)

When you post the code, snip out everything that does not help us see the
problem.

My advice in cases like this is to start small: don't try to implement your
desired behavior in the huge page tat you are actually going to be using.
Create a small test page with only the stuff needed to recreate the problem
and play with that one until you figure out how to make it happen.
Here is an example of maintaining a control's state after a submit:

<html><body><form method="post">
<input name="txtData" value="<%=request.form("txtData")%>">
<input type="submit">
</form></body></html>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #3
Like has been mentioned you need to get the submitted form values and put
them back into the appropriate control.

If it is a text box then what bob told you is the code to use.

If it is a select then use

<option value="<%=RS("Value")%>"<% If RS("value") = request.form("Select Box
Value") then response.write " selected"%>><%=RS("Value")%></option>

The check box would be <input type="checkbox" name="chkbox" <% if
request.form("chkbox") <> "" then response.write " checked" %>>

that should keep you going

"PT" <p4*******@hotmail.com> wrote in message
news:2d*************************@posting.google.co m...
I got a form with many text boxes, checkboxes and 3 drop downs. From
that 3, 2 are dependant. I can choose one drop down, and the next drop
down should display the dependant values of the first drop down
chosed. And I have a submite button to submit all these values to DB.

First problem: I cant keep the value of the selected text in the first
drop down. It always goes back to the first value. (but the asp site
extension changes accordingly).

Second problem: when the value of second drop down is updated, then
the text I inserted in those text boxes, and the checkboxes i checked
disappears!

I know its because the site is submitted again to update the second
drop down. But how could I keep the values of other elements even
though the drop down is updated?

Thank you. I'll post the code too, if anyone wants to look at it. (but
its a big one!!)

Jul 19 '05 #4
Personally I prefer to use a variable to keep things a little tidier (IMO)
and limit the calls to Request.Form

<%
sPostedValue=trim(Request.Form("Select Box Value"))
Do While not RS.EOF
sSelected=""
sValue=RS.Fields("Value")
if sPostedValue=sValue then sSelected=" selected"
%>
<option value="<%=sValue%>"<%=sSelected%>><%=sValue%></option>
<%
RS.MoveNext
Loop
%>
"Steven Scaife" <sp@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Like has been mentioned you need to get the submitted form values and put
them back into the appropriate control.

If it is a text box then what bob told you is the code to use.

If it is a select then use

<option value="<%=RS("Value")%>"<% If RS("value") = request.form("Select Box Value") then response.write " selected"%>><%=RS("Value")%></option>

The check box would be <input type="checkbox" name="chkbox" <% if
request.form("chkbox") <> "" then response.write " checked" %>>

that should keep you going

"PT" <p4*******@hotmail.com> wrote in message
news:2d*************************@posting.google.co m...
I got a form with many text boxes, checkboxes and 3 drop downs. From
that 3, 2 are dependant. I can choose one drop down, and the next drop
down should display the dependant values of the first drop down
chosed. And I have a submite button to submit all these values to DB.

First problem: I cant keep the value of the selected text in the first
drop down. It always goes back to the first value. (but the asp site
extension changes accordingly).

Second problem: when the value of second drop down is updated, then
the text I inserted in those text boxes, and the checkboxes i checked
disappears!

I know its because the site is submitted again to update the second
drop down. But how could I keep the values of other elements even
though the drop down is updated?

Thank you. I'll post the code too, if anyone wants to look at it. (but
its a big one!!)


Jul 19 '05 #5
p4*******@hotmail.com (PT) wrote in message news:<2d*************************@posting.google.c om>...
I got a form with many text boxes, checkboxes and 3 drop downs. From
that 3, 2 are dependant. I can choose one drop down, and the next drop
down should display the dependant values of the first drop down
chosed. And I have a submite button to submit all these values to DB.

First problem: I cant keep the value of the selected text in the first
drop down. It always goes back to the first value. (but the asp site
extension changes accordingly).
You need to retrieve the value of the drop down, and put a "SELECTED"
tag next to the item which is currently active. I.e., let's say you
have a drop down with values 1, 2, and 3. 2 is chosen. The ASP would
say something like:

<select name="period">
<option value="1" <%if period="1" then
response.write("selected")%>>One</option>
<option value="2" <%if period="2" then
response.write("selected")%>>Two</option>
<option value="3" <%if period="3" then
response.write("selected")%>>Three</option>
</select>


Second problem: when the value of second drop down is updated, then
the text I inserted in those text boxes, and the checkboxes i checked
disappears!

I know its because the site is submitted again to update the second
drop down. But how could I keep the values of other elements even
though the drop down is updated?


You have to retrieve the values of EVERY element on your page, and set
the initial value of those text boxes, check boxes, etc, to those
values retrieve when the page is refreshed.
Jul 19 '05 #6
PT
Hello all, Thanx for the inputs. But I think I should give u this
code, and the picture will be much more clear. First of all I created
this site in Dreamweaver and I deleted so many lines which I thought
wont do any good to solve the things I mentioned.

When I change the drop-down 'cboAbteilungID', it should filter the
drop-down 'cboArbeitsplatzID'. I tried to keep the selected value in
'cboAbteilungID', but its not working!

---------------------------------------------------------------------------------------

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** Edit Operations: declare variables
' *** DELETED variables declared by Dreamweaver

' Get value from select box
iAbteilungID = Trim(Request.QueryString("cboAbteilungID"))

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
' ******* DELETED *******
%>
<%
Dim rsPersonSoftware
Dim rsPersonSoftware_numRows

Set rsPersonSoftware = Server.CreateObject("ADODB.Recordset")
rsPersonSoftware.ActiveConnection = MM_userverwaltung_STRING
rsPersonSoftware.Source = "SELECT tblPersonID, tblSoftwareID FROM
dbo.tblPersonSoftware"
rsPersonSoftware.CursorType = 2
rsPersonSoftware.CursorLocation = 2
rsPersonSoftware.LockType = 3
rsPersonSoftware.Open()

rsPersonSoftware_numRows = 0
%>

<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
' **** DELETED *****
MM_editQuery = "SET NOCOUNT ON; insert into " & MM_editTable & " ("
& MM_tableValues & ") values (" & MM_dbValues & ");"&_
"SELECT SCOPE_IDENTITY() AS LastPersonID;"

If (Not MM_abortEdit) Then
' execute the insert
Dim iLastPersonID
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
'Get the last PersonID added, and insert datas
MM_editCmd.CommandType = 1 'adCmdText
Set rsPID = MM_editCmd.Execute
iLastPersonID = rsPID.Fields("LastPersonID").Value
' insert checked checkboxes values to BD
For i = 1 to 100 ' need to put in an upperbound that corresponds to
the total recordset count
If Request.Form("chkSoftware" & i) Then
'strSql1 = "INSERT into tblPersonSoftware (tblPersonID,
tblSoftwareID) values (" & iLastPersonID & ", " & i & ")"
rsPersonSoftware.Addnew
rsPersonSoftware("tblSoftwareID") = i
rsPersonSoftware("tblPersonID") = iLastPersonID
rsPersonSoftware.Update
End If
Next

MM_editCmd.ActiveConnection.Close
Set MM_editCmd = Nothing

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim PersonStatus
Dim PersonStatus_numRows

Set PersonStatus = Server.CreateObject("ADODB.Recordset")
PersonStatus.ActiveConnection = MM_userverwaltung_STRING
PersonStatus.Source = "SELECT StatusID, Status FROM dbo.tblStatus
ORDER BY Status ASC"
PersonStatus.CursorType = 0
PersonStatus.CursorLocation = 2
PersonStatus.LockType = 1
PersonStatus.Open()

PersonStatus_numRows = 0
%>
<%
Dim Arbeitsplatz
Dim Arbeitsplatz_numRows

Set Arbeitsplatz = Server.CreateObject("ADODB.Recordset")
Arbeitsplatz.ActiveConnection = MM_userverwaltung_STRING
Arbeitsplatz.Source = "SELECT ArbeitsplaetzeID, PCNummer FROM
dbo.tblArbeitsplatz WHERE tblAbteilungID='" & iAbteilungID & "'
ORDER BY PCNummer ASC"
Arbeitsplatz.CursorType = 0
Arbeitsplatz.CursorLocation = 2
Arbeitsplatz.LockType = 1
Arbeitsplatz.Open()

Arbeitsplatz_numRows = 0
%>
<%
Dim Abteilungen
Dim Abteilungen_numRows

Set Abteilungen = Server.CreateObject("ADODB.Recordset")
Abteilungen.ActiveConnection = MM_userverwaltung_STRING
Abteilungen.Source = "SELECT AbteilungID, Abteilung, Standort,
tblStandortID FROM dbo.Abteilungen ORDER BY Abteilung ASC, Standort
ASC "
Abteilungen.CursorType = 0
Abteilungen.CursorLocation = 2
Abteilungen.LockType = 1
Abteilungen.Open()

Abteilungen_numRows = 0
%>
<%
Dim rsSoftware
Dim rsSoftware_numRows

Set rsSoftware = Server.CreateObject("ADODB.Recordset")
rsSoftware.ActiveConnection = MM_userverwaltung_STRING
rsSoftware.Source = "SELECT SoftwareID, SoftwareName FROM
dbo.tblSoftware ORDER BY SoftwareName ASC"
rsSoftware.CursorType = 0
rsSoftware.CursorLocation = 2
rsSoftware.LockType = 1
rsSoftware.Open()

rsSoftware_numRows = 0
%>
<%
Dim rsPerson
Dim rsPerson_numRows

Set rsPerson = Server.CreateObject("ADODB.Recordset")
rsPerson.ActiveConnection = MM_userverwaltung_STRING
rsPerson.Source = "SELECT PersonID FROM dbo.tblPersonen"
rsPerson.CursorType = 0
rsPerson.CursorLocation = 2
rsPerson.LockType = 1
rsPerson.Open()

rsPerson_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsSoftware_numRows = rsSoftware_numRows + Repeat1__numRows
%>
<html>
<head>
<title>New Personen - Userverwaltung</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script language="JavaScript" type="text/JavaScript">
<!--
** deleted the code for form validation
//-->
</script>
</head>

<body>

<form action="<%=MM_editAction%>" method="POST" name="frmNewPerson"
onSubmit="MM_validateForm('Vorname','','R','Name', '','R','Email','','NisEmail');return
document.MM_returnValue">
<table>
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td> <input type="text" name="Name" value="" size="32"> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Zusatzsoftware:</td>
<td> <%
While ((Repeat1__numRows <> 0) AND (NOT rsSoftware.EOF))
%>
<input type="checkbox"
name="chkSoftware<%=(rsSoftware.Fields.Item("Softw areID").Value)%>"
value="<%=(rsSoftware.Fields.Item("SoftwareID").Va lue)%>">
<%=(rsSoftware.Fields.Item("SoftwareName").Value)% >
<% Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsSoftware.MoveNext()
Wend
%>
</table></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Status:</td>
<td> <select name="cboStatusID">
<%
While (NOT PersonStatus.EOF)
%>
<option value="<%=(PersonStatus.Fields.Item("StatusID").Va lue)%>"
<%If (Not isNull((PersonStatus_first))) Then If
(CStr(PersonStatus.Fields.Item("StatusID").Value) =
CStr((PersonStatus_first))) Then Response.Write("SELECTED") :
Response.Write("")%>
<%=(PersonStatus.Fields.Item("Status").Value)%> </option> <%
PersonStatus.MoveNext()
Wend
If (PersonStatus.CursorType > 0) Then
PersonStatus.MoveFirst
Else
PersonStatus.Requery
End If
%>
</select> </td>
<tr valign="baseline">
<td nowrap align="right">Abteilung:</td>
<td> <select name="cboAbteilungID"
onChange="window.location='<%=Request.Servervariab les("Script_Name")%>?cboAbteilungID='+this.value;" >
<%
While (NOT Abteilungen.EOF)
%>
<option <% If Abteilungen("AbteilungID") =
Request.QueryString("cboAbteilungID") Then Response.Write("selected")
End If %> value="<%=(Abteilungen.Fields.Item("AbteilungID"). Value)%>">
<%=(Abteilungen.Fields.Item("Abteilung").Value)% >,
<%=(Abteilungen.Fields.Item("Standort").Value)%>
</option>
<%
Abteilungen.MoveNext()
Wend
If (Abteilungen.CursorType > 0) Then
Abteilungen.MoveFirst
Else
Abteilungen.Requery
End If
%>
</select> </td>
</tr>
</tr>
<tr valign="baseline">
<td nowrap align="right">PC-Nummer:</td>
<td> <select name="cboArbeitsplatzID">
<%
If Arbeitsplatz.EOF Then
Response.Write("<option>(Kein PC zugeordnet)</option>")
Else
While (NOT Arbeitsplatz.EOF)
%>
<option value="<%=(Arbeitsplatz.Fields.Item("Arbeitsplaetz eID").Value)%>"
<%If (Not isNull((PersonStatus_first))) Then If
(CStr(Arbeitsplatz.Fields.Item("ArbeitsplaetzeID") .Value) =
CStr((PersonStatus_first))) Then Response.Write("SELECTED") :
Response.Write("")%><%=(Arbeitsplatz.Fields.Item("PCNummer").Value)%> </option>

<%
Arbeitsplatz.MoveNext()
Wend
If (Arbeitsplatz.CursorType > 0) Then
Arbeitsplatz.MoveFirst
Else
Arbeitsplatz.Requery
End If
End If
%>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td> <input type="submit" value="Datensatz einf&uuml;gen"> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="frmNewPerson">
</form>

PersonStatus.Close()
Set PersonStatus = Nothing
%>
<%
Arbeitsplatz.Close()
Set Arbeitsplatz = Nothing
%>
<%
Abteilungen.Close()
Set Abteilungen = Nothing
%>
<%
rsSoftware.Close()
Set rsSoftware = Nothing
%>
<%
rsPerson.Close()
Set rsPerson = Nothing
%>
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Smriti Dev | last post by:
Hi, I have a drop down menu with a listing of communities and I use it to select a community, selecting a letter ie. "T" , I get bumped to the "T" section to choose communities that start with...
1
by: Stewart | last post by:
Hi all, hoping one of you may be able to throw up an idea on the following. I have an asp.net page with a drop-down and a user control inside. The user control should be cached in one way or...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
9
by: Matt Tapia | last post by:
I having a problem that receives the following error: Specified cast is not valid And I need some help. Here is what is happening: I have a form with a drop-down control that contains a list...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
2
by: JimS | last post by:
Ok, I am trying to populate two drop down boxes with the results of a query. I have the first one set up and working but I am stuck on how to pass the results of the first query as a constraint for...
1
by: russot00 | last post by:
I have 3 drop down menus that are used in a search to locate restaurants in a db. All of the drop down menus function, a search can be submitted with any combination of drop downs and the results are...
5
by: sbettadpur | last post by:
hello everybody, In my application i am using three dependant drop down boxes for that one i am using ajax to load the values in dependant drop downs eg A -> first drop down box its loading...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.