Click to See Complete Forum and Search --> : [RESOLVED] Issue with using subs when there is a form tag.


Lykins
06-18-2009, 04:21 PM
I havn't set down and did web development in about two years and no longer have some of my code to fall back in. I was able to merge a few code snippits that I found together to accomplish what I needed which was a dynamic drop down list for several levels. I cut my code down to a workable version. The two select boxes fill correctly until I put them in a form. Once it goes inside the <form> tag it stops populating. The code I used at my last company was complicated javaScript code that I wanted to avoid.

Is there anything that I'm missing in my code that would cause it to not work? I have moved the segments around and everything works until I do the form tag.

Thank you,
Patrick

<!-- Stripped down version
Code works perfectly unless I uncomment the form.-->
<!-- <form name="frmSubmit"> -->
<select id=appDept1></select>
<select id=appPos1></select>

<%
Dim adoCon 'Holds the Database Connection Object
Dim rsObj1 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query to query the database
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL_SERVER;UID=<username>;PWD=<password>;DATABASE=<database>"
Set rsObj1 = Server.CreateObject("ADODB.Recordset")

'Get departments
strSql = "Select * from appDept order by aDName"
Set rsObj1 = adoCon.Execute(strSql)
dCount = 1
pName="""NA"""
caselist1=""
'Loop through Departments
do while not rsObj1.eof
pName=pName+","""+rsObj1.fields("adname").value+""""
'Get Positions
strSql = "Select * from appPosition where aDID ="+cstr(rsObj1.fields("adid").value)+ " order by apName"
Set rsObj2 = adoCon.Execute(strSql)
pCount = 0
'Loop through Positions
do while not rsObj2.eof
if pCount = 0 then
caselist1 = caselist1+"Case "+cstr(dCount)+vbCRLf+"load_combo appPos1, split("""
else
caselist1 = caselist1 + ","
end if
caselist1=caselist1+rsObj2.fields("apName").value
rsObj2.movenext
pCount=1
loop
if pCount > 0 then
caselist1=caselist1+""","","")"+vbCRLF
end if
dCount=dCount+1
rsObj1.movenext
loop
%>

<script language=vbscript>
option explicit

sub add_option (select_id, value, text)
dim opt : set opt = document.createelement("option")
opt.value = value
opt.text = text
select_id.add opt
set opt = nothing
end sub
'The next subroutine populates a select box with the contents of an array:'

sub load_combo (select_id, option_array)
dim i: for i = 0 to ubound(option_array)
add_option select_id, i, option_array(i)
next
end sub
' And then a final subroutine clears the contents of a drop-down list box:'

sub clear_combo (select_id)
select_id.options.length = 0
end sub
'With the subroutines in place an array is required - this will be used to populate the first of the select boxes:'

'Editable: Add all load routines here'
load_combo appDept1, array (<%=pName%>)

'Editable: Duplicate this for each dropdown you have'
sub appDept1_onchange
clear_combo appPos1
select case appDept1.value
<%=caselist1%> 'Case Loop that we built above.'
end select
end sub

</script>

</form>

<!-- END FILE -->

russell
06-22-2009, 09:23 AM
you've mixed up your server side and client side scripting looks like

Lykins
07-02-2009, 01:12 PM
Yep. It's been about two years since I've done any major web development and forgot how to ride the bike. All of the sites I used to use are apparently now defunct. I'll go ahead and answer my question though in case someone comes across this. I got pulled to a new project and when I came back to it today I realized I didn't qualify the form name in front of the combo.

load_combo frmSubmit.appDept1, array (<%=pName%>)