Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing array with onchange event 1

Status
Not open for further replies.

mts176

MIS
Apr 17, 2001
109
US
I know this might be a simple question, but I am beating my head against a wall.

I have a dropdown box that when changed I need to pass an array to a VBscript subroutine. Everytime I try I get an error. Any suggestions?

Code:
<%
					do while not rsAC.eof 						
						Redim Preserve RS_Array(6, i + 1)						
						RS_Array(1,i + 1) = rsAC("Child_ID")						
						RS_Array(2,i + 1) = rsAC("Answer_ID")
						RS_Array(3,i + 1) = rsAC("Question_ID")
						RS_Array(4,i + 1) = rsAC("Child_Text")
						RS_Array(5,i + 1) = rsAC("Display_Order")
						RS_Array(6,i + 1) = rsAC("Active")						
						i = i + 1
						rsAC.movenext
					loop

%>


					   <SELECT name="<%=rsGQ.Fields("FORM_FIELD_NAME")%>" onChange="call NewDropdown('<%=RS_Array%>','<%=rsGQ.Fields("FORM_FIELD_NAME")%>')"><%
 
is the vbscript server side or client side (ie are you using it like you would use javascript) as you can't call an asp function from the page, it needs to be done after a submit

}...the bane of my life!
 
I amusing it like javascript. I can use javascript if that would make this work.

When I load the page, I hide an empty dropdown(hSelect) box. After the user clicks a full visible dropdown(fSelect), I want to display the hidden(hSelect) one with data from an array that was created when the page was loaded.

Page Load
--> Query DB, fill visible dropdown(vSelect), create and populate array.

After page load user changes (vSelect)
--> send array to a function/sub to populate (hSelect), show (hSelect)
Hopefully this helps explain a little better
 
you could use javascript to show the other dropdown somthing like.

the hidden select is set up like

<select id="fromdb" name="fromdb" style="display:none">

the function to display this is
onchange(show('idFromDb'))

function show(id){
document.getElementById(id).style.display="inline"
}

}...the bane of my life!
 
So you are saying create the dropdown(hSelect) while the page is loaded but hide it and when a user selects the correct item in the (vSelect) I would show the hidden(hSelect) dropdown?
 
Creating the dropdown and hiding it will not work.

For 1 dropdown box there can be up to n different data sets to choose from. If someone chooses medical student then the hidden dropdown will contain years 1-4, if they choose nurse, the dropdown will contain the different kinds of nurses. This is to be 100% dynamic so I can not hard code anything.

I need to get an array into a function that I can call on from an onChange event in the dropdown selection.
 
This is my code. I don't know how else to ask this. If anybody has a suggestion on a different way of doing this please let me know.

Code:
<script language=vbscript>
sub NewDropdown(fieldid, myarray)

	'Set objList = Document.frmUserProfile.Item(0)
	Set objList = document.getElementById(fieldid)

	Set objOption = Document.CreateElement("OPTION")
	objOption.InnerHTML = "Chicken"
	objList.AppendChild(objOption)
	Set objOption = Document.CreateElement("OPTION")
	objOption.InnerHTML =  "Potatoes"
	objList.AppendChild(objOption)
	Set objOption = Document.CreateElement("OPTION")
	objOption.InnerHTML =  "Milk"
	objList.AppendChild(objOption)
	document.getElementById(fieldid).style.visibility = "Visible"
end sub	
</script>
<%

%>

		<form action="<%=request.Servervariables("URL")%>" name="frmUserProfile" method="post" ID="Form1">
		<table width=100% border=0 cellpadding=0 cellspacing=1 ID="Table2">
			<tr><td colspan=4 align=left>&nbsp;</td></tr>
<%
x = 0
				strSQL_DemogAnswers = "select * from id0_request_answers_child "

				set rsAC = conn.Execute(strSQL_DemogAnswers)	
							
				if not rsAC.eof then					
					do while not rsAC.eof 						
						Redim Preserve RS_Array(6, x + 1)						
						RS_Array(1,x + 1) = rsAC("Child_ID")						
						RS_Array(2,x + 1) = rsAC("Answer_ID")
						RS_Array(3,x + 1) = rsAC("Question_ID")
						RS_Array(4,x + 1) = rsAC("Child_Text")
						RS_Array(5,x + 1) = rsAC("Display_Order")
						RS_Array(6,x + 1) = rsAC("Active")						
						i = i + 1
						rsAC.movenext
					loop			
				end if
		i=1
	Do while not rsGQ.EOF
				'//sets up the table for all elements that are not associated with Height
				%><tr align=right ><td><span class="fieldTitle">&nbsp;<%=rsGQ.Fields("question_text")%>&nbsp;</span></td>
<td align=left><%

				
				'//Retrieves the next set of answers from the database
				'//it also retrieves any answers that were provided by the user
				strSQL_DemogAnswers = "SELECT ANSWER_TEXT, ANSWER_ID "
						'//This query was originally set up to get one answer from the user per question
						'//with the checkboxes the user can enter multiple answers, this caused an error.  
								If rsGQ.Fields("RESPONSE_TYPE") <> "checkbox" then
									strSQL_DemogAnswers = strSQL_DemogAnswers & " , (Select demog_answer_id from TBL_DEMO_USER_ANSWERS  " & _
									" WHERE user_id = "&UserID&" and demog_question_id=" & rsGQ.Fields("QUESTION_ID") & ") as DUA "
								End if
									strSQL_DemogAnswers = strSQL_DemogAnswers & " FROM id0_request_answers t Where t.QUESTION_ID = " & rsGQ.Fields("QUESTION_ID") & " " & _
									" ORDER BY ANSWER_TEXT ASC "
									'response.Write strSQL_DemogAnswers
				set rsGA = conn.Execute(strSQL_DemogAnswers)
				IF 0 <> Err.number THEN
					'// the requested form was not in the database.
					bMinorError = TRUE
				END IF
				'if i > 4 then response.End
				%>
  				<SELECT name="<%=rsGQ.Fields("FORM_FIELD_NAME")%>" id=<%=i%> onChange="NewDropdown(<%=i+1%>, <%RS_Array%>)"><%
				%><option value=-1>Select...</option><%
				Do while not rsGA.EOF
					if not isnull(rsGA("DUA")) and rsGA("DUA")<> "" then
						UserAnswer = rsGA("DUA")
					else
						UserAnswer = 0
					End If
					if cdbl(rsGA("ANSWER_ID")) = cdbl(UserAnswer) then
						%><option value="<%=rsGA.Fields("ANSWER_ID")%>" selected><%=rsGA.Fields("ANSWER_TEXT")%></option><%	
					Else
						%><option value=<%=rsGA.Fields("ANSWER_ID")%>><%=rsGA.Fields("ANSWER_TEXT")%></option><%					
					end if
					rsGA.MoveNext
				loop
				%>
				<option value=0>Other</option>
				</select>
				<%							
				i = i + 1%>
				<select id=<%=i%> name="<%=rsGQ.Fields("FORM_FIELD_NAME")%>child" style="visibility: hidden;"></select>
				<%				
			i = i + 1
			rsGQ.MoveNext
					%></td></tr><tr><td colspan=2>&nbsp;</td></tr><%			
			set rsGA = nothing  '//Close the connection string for the System Demographic Answers
	Loop
	set rsGQ = nothing '//Close the connection string for the System Demographic Questions
%>
I can get the sub routine to put the static information into the hidden dropdown, but I can not get the "RS_Array" to pass from the dropdown to the subroutine. Please help if you can
 
How do i get my information from my database into the javascript to populate my array?
 
loop a response.write into the javascript

<script>
<%
for n= 0 to ubound(arr,2)
response.write("mammal["&n&"] = "&arr(1,n)&"vbcrlf")
next
%>
</script>



}...the bane of my life!
 
sorry typo

<script>
<%
varTest = "asd,asd,asasdas,asdasd"
arr = split(varTest,",")
for n= 0 to ubound(arr)
response.write("mammal["&n&"] = "&arr(n)&vbcrlf)
next
%>
</script>

}...the bane of my life!
 
oh for goodness sake, must test scripts b4 posting!!!!

<script>
var mammal= new Array();
<%
varTest = "asd,asd,asasdas,asdasd"
arr = split(varTest,",")
for n= 0 to ubound(arr)
response.write("mammal["&n&"] = '"&arr(n)&"'"&vbcrlf)
next
%>
for(n=0;n<mammal.length;n++){
alert(mammal[n])
}
</script>

}...the bane of my life!
 
Alternatively:
Code:
<script>
<%
varTest = "asd,asd,asasdas,asdasd"
arr = split(varTest,",")
for n= 0 to ubound(arr)
%>
mammal[<%=n%>] = "<%=arr(n)%>"; 
<% next %>
</script>
Dave, you're missing some quotes in your syntax, it should read:
Code:
 response.write("mammal[" & n & "] = """ & arr(n) & """;" & vbcrlf)
The value arr(n) is a string, so it has to be quoted.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top