Output of select values are numerals instead of state and county

B

Bubba

I have a dynamic pulldown list (ASP with javascript) that when a user
picks a state, the corresponding counties for that state appear in a
dynamic second pulldown list. When I submit the form, the values for
state and county are numerals 1 (for the state) and 2 (for the county
selected) and not the values for the state and county
????
any help appreciated!


<!--#include file="dbaseconnection.asp" -->
<%
Dim rsMain
Dim rsMain_numRows

Set rsMain = Server.CreateObject("ADODB.Recordset")
rsMain.ActiveConnection = conn_STRING
rsMain.Source = "SELECT * FROM state_details ORDER BY state2 ASC"

rsMain.Open()

rsMain_numRows = 0
%>
<%
Dim rsSub
Dim rsSub_numRows

Set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = conn_STRING
rsSub.Source = "SELECT * FROM county_details ORDER BY county ASC"

rsSub.Open()

rsSub_numRows = 0
%>

<script language="JavaScript">
<!--

var arrDynaList = new Array();
var arrDL1 = new Array();

arrDL1[1] = "state"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "county"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList; // No need to do anything here

<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue,
oDynaListRS

txtDynaListRelation = "fkid" ' Name of recordset field relating to
parent
txtDynaListLabel = "county" ' Name of recordset field for child
Item Label
txtDynaListValue = "couid" ' Name of recordset field for child
Value
Set oDynaListRS = rsSub ' Name of child list box recordset

Dim varDynaList
varDynaList = -1

Dim varMaxWidth
varMaxWidth = "1"

Dim varCheckGroup
varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value

Dim varCheckLength
varCheckLength = 0

Dim varMaxLength
varMaxLength = 0

While (NOT oDynaListRS.EOF)

If (varCheckGroup <>
oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
varCheckLength = 0
End If
%>
arrDynaList[<%=(varDynaList+1)%>] = "<
%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>"
arrDynaList[<%=(varDynaList+2)%>] = "<
%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>"
arrDynaList[<%=(varDynaList+3)%>] = "<
%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>"
<%
If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) >
len(varMaxWidth)) Then
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
End If
varCheckLength = varCheckLength + 1
varDynaList = varDynaList + 3
oDynaListRS.MoveNext()
Wend

If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
%>

//-->
</script>


<script language="JavaScript">
<!--
function setDynaList(arrDL){

var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
var arrList = arrDL[5];

clearDynaList(oList2);

if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}

populateDynaList(oList2, oList1[oList1.selectedIndex].value,
arrList);
return true;
}

function clearDynaList(oList){

for (var i = oList.options.length; i >= 0; i--){
oList.options = null;
}

oList.selectedIndex = -1;
}

/*This is a modified function from the original MM script. Mick White
added the first line of oList so there would be an initial selection.
Needed this if there is only 1 child menu item, otherwise, the single
child menu item would be already hihghlighted and you can not select
it. Also good for validation purposes so you can set the .js
validation to not allow the first selection.
*/

function populateDynaList(oList, nIndex, aArray){
oList[oList.length]= new Option("Please Select");
for (var i = 0; i < aArray.length; i= i + 3){
if (aArray == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1],
aArray[i + 2]);
}
//oList.size=oList.length //You need to comment out this line of the
function if you use this mod
}

//A quick mod here, I changed the ==0 to ==1 so that the length
//takes into account the Please select option from above.
if (oList.options.length == 1){
oList.options[oList.options.length] = new Option(":: No
SubCategories Available ::");
}
oList.selectedIndex = 0;
}

//-->
</script>

<select name="state" id="state" size="10"
onChange="setDynaList(arrDL1)" class="select-type1">
<%
While (NOT rsMain.EOF)
%>
<option value="<%=(rsMain.Fields.Item("staid").Value)%>"><
%=(rsMain.Fields.Item("statefull").Value)%></option>
<%
rsMain.MoveNext()
Wend
If (rsMain.CursorType > 0) Then
rsMain.MoveFirst
Else
rsMain.Requery
End If
%>
</select>
<!-- here's the child/sub box 'county' , will display under not
side by side -->
<select name="county" id="county" size="10" class="select-type1">
</select>


<%
rsMain.Close()
Set rsMain = Nothing
%>
<%
rsSub.Close()
Set rsSub = Nothing
%>
 
L

Lee

Bubba said:
I have a dynamic pulldown list (ASP with javascript) that when a user
picks a state, the corresponding counties for that state appear in a
dynamic second pulldown list. When I submit the form, the values for
state and county are numerals 1 (for the state) and 2 (for the county
selected) and not the values for the state and county
????
any help appreciated!

This is a Javascript newsgroup. Please post the Javascript code
and related HTML, not your server-side code that generates it.


--
 
B

Bubba

I did just that, I posted all the javascript blocks. sorry for it
being lengthy (as i needed to post the accompanying ASP/sql , and the
form tags)
 
L

Lee

Bubba said:
I did just that, I posted all the javascript blocks. sorry for it
being lengthy (as i needed to post the accompanying ASP/sql , and the
form tags)

I'm saying to leave out the ASP code.
Show us *only* the generated page.


--
 
O

OmegaJunior

oList.options[oList.options.length] = new Option(aArray[i + 1],
aArray[i + 2]);

This line states that every option will have both a text and an associated
value. I didn't read that deep into the code, but if that associated value
is a numeral, that's also what your form will submit.

To overcome, change it into this:
oList.options[oList.options.length] = new Option(aArray[i + 1]);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top