By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,839 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,839 IT Pros & Developers. It's quick & easy.

Output of select values are numerals instead of state and county

P: n/a
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).Va lue)%>"
arrDynaList[<%=(varDynaList+2)%>] = "<
%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value )%>"
arrDynaList[<%=(varDynaList+3)%>] = "<
%=(oDynaListRS.Fields.Item(txtDynaListValue).Value )%>"
<%
If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Val ue) >
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[i] = 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[i] == 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
%>

Mar 26 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
--

Mar 26 '07 #2

P: n/a
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)
On Mar 26, 11:00 am, Lee <REM0VElbspamt...@cox.netwrote:
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.

--

Mar 26 '07 #3

P: n/a
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.
--

Mar 26 '07 #4

P: n/a
Bubba said the following on 3/26/2007 2:32 PM:
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)
No, you posted the ASP code that generates your HTML/JS. Open your page
in the browser, right click>View Source and post *that* source code. Or,
even better, is to post a URL to a sample page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 26 '07 #5

P: n/a
On Mon, 26 Mar 2007 18:17:06 +0200, Bubba <ar*****@yahoo.comwrote:
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]);
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 31 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.