Click to See Complete Forum and Search --> : dropdown not maintaining state


simflex
09-17-2003, 01:04 PM
Can you please, please help.

I have a dynamic dropdown list box where the second dropdown is populated with data from the first dropdown.
This works fine.
This is a two-page form. After completing first page, you click continue to go to the second page.
Problem I discovered is that when the client clicks the back button to go back to first page,or an error is encountered and the client needs to go back to first page to correct it, the value in the dropdown is cleared requiring the client to select the first dropdown again to repopulate the second.
The rest of the values in every input text box is not cleared. Only the dropdown box is getting cleared.
There is got to be a way to fix this problem.
Please help.

Second, I am required to expand the dependent list box to 3.
Which means that the second and third dropdown boxes are populated with data from the first dropdown.
For instance, the first dropdown will now be employee.
Once you select a name for the first dropdown box, the second and third are populated based on the value from the first dropdown.
If anyone can help with one or both of these, I will GREATLY appreciate it.
Here is the current dependent dropdown list where second dropdown is populated with data from the first dropdown.
This is also the one where values disappear once you click the back button.
<%
Response.Buffer = True
set safetyDB = Server.CreateObject("ADODB.Connection")
safetyDB.Open "dsn=safety"
sql = "SELECT * FROM theEmp "
set rs = safetyDB.execute(sql)
%>


<head>
<script language = "JavaScript">

function subcat()
{
cat = document.subad.org[document.subad.org.selectedIndex].value;
url = "CorrectEmployeeData.asp?cat=";
url = url + cat;
window.location.href = url;
}
function sublist(inform, selecteditem)
{
inform.division.length = 0
<%
count= 0
y=0
do while not rs.eof
%>
x = <%= trim(y) %>
subcat = new Array();
division = "<%= trim(rs("division"))%>"
org = "<%= trim(rs("org"))%>"
empid = "<%= trim(rs("empid"))%>"
subcat[x,0] = division;
subcat[x,1] = org;
subcat[x,2] = empid;

if (subcat[x,1] == selecteditem)
{
var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,2])
inform.division.options[inform.division.length]=option<%=trim(count)%>
}
<%
count = count + 1
y = y + 1
rs.movenext
loop
%>
}
</script>
</head>
<body>
<TABLE border="2" bgcolor="ffffff" width="100%">

<TR>
<TD ALIGN=left width="65%"><font size="-1" style="arial8">Employee's Org</font></TD>

<TD ALIGN=LEFT>
<%
cat = Request.QueryString("cat")
sql = "SELECT * from org order by orgcode desc"
set rs = safetyDB.execute (sql)
%>
<SELECT id=org name=org onChange = "sublist(this.form, document.subad.org[document.subad.org.selectedIndex].value)">
<%
do until rs.eof
isSelected=""
if rs("orgid")=rs("orgid") then
isSelected=" Selected "
end if
%>
<OPTION value="<%= rs("orgID")%>" <%=isSelected%>><% = rs("orgCode")%></OPTION>

<%
rs.movenext
loop


set rs = nothing
%>
</SELECT>
<%if errorcode1 = "yes" then%> <font color="#FF0000"><strong>*please insert the employee's org
</strong> </font> <%end if%>
</TD>

<TD ALIGN=left width="65%"><font size="-1" style="arial8">Division</font></TD>

<TD ALIGN=LEFT>

<select id = "division" name="division">
<option value="invalid">-----------</option>
</select>
</TD>
</TR>

</TABLE>
</body>

Ribeyed
09-17-2003, 05:58 PM
hi,
i can help you with the first question but not the second one.

You need to post the page back to the same page to start with. Then you can use code like this within the selectbox tags.


<select>
<option value="value" <%if thevalue = thevalueoftheoption then response.write "selected" end if%>>text here</option>
</select>

simflex
09-17-2003, 06:20 PM
hi, I remember you.
Thanks for all the past help.
The problem I will have with posting the page back to itself is there are 3 pages involved here.
I had to split the page into 3.
Page1 which contains this dropdown, posts to page 2 with some hidden fields from page1.
page2 then posts to page3. page3 invokes a stored procedure that processes data and submits to the database.
I am sure there is an easier way of doing this.
This is a trimmed down version of our accidentRec/StoreRec code.
It works now but it is really done the way that I wanted it.

Ribeyed
09-17-2003, 06:22 PM
can't see any reason why you can't postback to same page. I have a page that looks like 5 pages but the page is split and only displays 1 part at a time. Its no way easy to do but it is doable.

simflex
09-17-2003, 08:33 PM
Ok, I will do some research to see if I can do this the way you suggested.
This is something that I wouldn't want to spend more than than 2 days on.
The only reason I wanted to fix this is because the client is forced to do it "my way" which is wrong.
My way in the sense that if for some reason they go back to page1, they must repopulate second dropdown from first dropdown instead of the value of second dropdown being maintained after clicking the back button.
If you have some samples of how I can do this, please advise. It will be greatly appreciated.

txmail
09-17-2003, 10:36 PM
Have you tried using cookies? Once the form was submitted from the frist page I would put the first cookies the values that they filled out, that way if there is an error on the second page hopefully what they had filled out on the first page would have been a cookies, and when they go back the page can just read the cookie, just dont forget to clean up the cookies once you are done with them, nobody likes stray cookies (they invite roaches...)

simflex
09-18-2003, 06:49 AM
I have tried that; I have tried disabling the back button, adding a hidden field for the dropdown and passing a value to it thereby forcing the user to go back with the a defined back button.
That didn't work.
As indicated, every other form fields retain their values except the dropdown.
There is a link I found that not only shows a demo and sample codes of how this can be accomplished, it also shows a demo of how you can have a tripple dependent list box which is the other issue that I have.
Their code is way too complicated for me to understand.
Here is the link for anyone interested:

http://www.atgconsulting.com/oodynlistbox2.asp

txmail
09-18-2003, 08:22 AM
Well you also need to set the value of the options to <OPTION SELECTED>, a simple if then loop will suffice.