Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 03:32 PM
PT
Guest
 
Posts: n/a
Default Problem with dependant drop down

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!!)
  #2  
Old July 19th, 2005, 03:32 PM
Utada P.W. SIU
Guest
 
Posts: n/a
Default Re: Problem with dependant drop down

I thought you better provides the source to us then we can know it in depth


  #3  
Old July 19th, 2005, 03:32 PM
Bob Barrows [MVP]
Guest
 
Posts: n/a
Default Re: Problem with dependant drop down

PT wrote:[color=blue]
> 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!!)[/color]


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"


  #4  
Old July 19th, 2005, 03:33 PM
Steven Scaife
Guest
 
Posts: n/a
Default Re: Problem with dependant drop down

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" <p4pradeep@hotmail.com> wrote in message
news:2d868f1e.0410140132.9e5c2ae@posting.google.co m...[color=blue]
> 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!!)[/color]


  #5  
Old July 19th, 2005, 03:33 PM
TomB
Guest
 
Posts: n/a
Default Re: Problem with dependant drop down

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:%23J4TFUfsEHA.2516@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
Box[color=blue]
> 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" <p4pradeep@hotmail.com> wrote in message
> news:2d868f1e.0410140132.9e5c2ae@posting.google.co m...[color=green]
> > 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!!)[/color]
>
>[/color]


  #6  
Old July 19th, 2005, 03:33 PM
Larry Bud
Guest
 
Posts: n/a
Default Re: Problem with dependant drop down

p4pradeep@hotmail.com (PT) wrote in message news:<2d868f1e.0410140132.9e5c2ae@posting.google.c om>...[color=blue]
> 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).[/color]

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>




[color=blue]
> 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?[/color]

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.
  #7  
Old July 19th, 2005, 03:33 PM
PT
Guest
 
Posts: n/a
Default Re: Problem with dependant drop down

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("")%>[color=blue]
><%=(PersonStatus.Fields.Item("Status").Value)%> </option>[/color]
<%
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("")%>[color=blue]
><%=(Arbeitsplatz.Fields.Item("PCNummer").Value)%> </option>[/color]
<%
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
%>
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles