i am trying to make a javascript function that contains some asp code so i can bring info from a database and then loop through the code and write out all of the "Column2" variables where the "Column1" Variables match a certain number function clickcombo(elem1,elem2,SelectedItem){ clearcombo(elem2); 'ignore the elem1, elem2, clearcombo and populatecombo2. the main problem 'i am having is getting SI to equal the javascript variable SelectedItem; <% Dim SI Dim Count SI = %> SelectedItem; <% Count = 0 Dim cnCity Dim rsCity Set cnCity = Server.CreateObject("ADODB.Connection") Set rsCity = Server.CreateObject("ADODB.Recordset") cnCity.Open Application("Data_Server") rsCity.Open "get_City '" & CSTR(SI) & "'", cnCity, adOpenStatic, adLockReadOnly do while not rsCity.EOF if SI = rsCity("SID") then 'decide whether StateID = The Selected StateID from the State Dropdown Box Count = Count + 1 Response.Write "array1[" & Count & "].Value = " & rsCity("City") & ";" & vbcrlf 'Write new JavaScript Array Value End If loop Count.Close cnCity.Close Set cnCity.Nothing rsCity.Close Set rsCity.Nothing %> populatecombo2(elem2, elem1[elem1.selectedIndex].value, array1); clear array1 'i also don't know how to clear the array in javascript return true; } any help would be very appreciated
Think of it this way - SelectedItem exists in the browser, literally - there's a piece of memory with a value in it; your script runs on the server, miles away. How can you assign one to another? You got it all mixed up. This is what you are thinking about (in this case your server code generates JS code): var js_var = <%= some-vb-code %> The only way to communicate a JS variable into the script is to submit it with the next HTTP request (e.g. using forms, cookies, JS code, etc). Then use the appropriate server mechanism to retrieve the value. For example: <% SI = Request.QueryString("SelectedItem") %> J.D.
ah, thank you very much. i didn't realize i could just request it. i have only been doing asp for 2 weeks so this is new territory for me. thx for the help