1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

vbscript variable = javascript variable

Discussion in 'C#' started by Hazzardusa, Aug 16, 2005.

  1. #1
    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
     
    Hazzardusa, Aug 16, 2005 IP
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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.
     
    J.D., Aug 16, 2005 IP
  3. Hazzardusa

    Hazzardusa Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    Hazzardusa, Aug 17, 2005 IP