passing javascript variable into asp variable using vbscript

Discussion in 'ASP General' started by Jonas Daunoravicius, Jul 1, 2003.

  1. The subject pretty much sums up what I need to do. Here is what I
    have so far, but still can't figure out how to get it working:

    <script language="javascript" type="text/javascript">
    function fillForm()
    {
    // split the query string into pieces
    var qs = location.search.substr(location.search.indexOf("?")+1);
    qs = qs.split("&");
    alert(qs); // qs is the variable that I need to pass into a
    // vbscript var. This actually works up to here.
    '<%the_name%>' = qs // this line does not work, but is what I need
    // to do.
    }
    </script>


    later in the code:
    <%
    Response.write ("<script>fillForm();</script>")
    Response.write("This is the variable: " & the_name)
    %>

    On the page it obviously comes up as "This is the variable: " and that
    is it...blank for the_name.

    I need to use javascript to get the variables out of the url, such as:
    http://www.x.com/test.asp?Dell Computer Corp
    qs will then end up being "Dell Computer Corp" and I need to make a
    vbscript variable to also be that so I can query/load/etc certain
    stuff in asp to display on the site.

    Thanks for your help!

    - Jonas
    Jonas Daunoravicius, Jul 1, 2003
    #1
    1. Advertising

  2. Jonas Daunoravicius

    Comcast Guest

    I don't think it is possible, because the vbscript (the server code) will
    always be executed before the page ever reaches the browser where the
    javascript is executed. Please correct me if I am wrong. I wish someone
    would post a website or write a book on the subject of communication between
    server-side and client-side scripts.

    Phil

    "Jonas Daunoravicius" <> wrote in message
    news:...
    > The subject pretty much sums up what I need to do. Here is what I
    > have so far, but still can't figure out how to get it working:
    >
    > <script language="javascript" type="text/javascript">
    > function fillForm()
    > {
    > // split the query string into pieces
    > var qs = location.search.substr(location.search.indexOf("?")+1);
    > qs = qs.split("&");
    > alert(qs); // qs is the variable that I need to pass into a
    > // vbscript var. This actually works up to here.
    > '<%the_name%>' = qs // this line does not work, but is what I need
    > // to do.
    > }
    > </script>
    >
    >
    > later in the code:
    > <%
    > Response.write ("<script>fillForm();</script>")
    > Response.write("This is the variable: " & the_name)
    > %>
    >
    > On the page it obviously comes up as "This is the variable: " and that
    > is it...blank for the_name.
    >
    > I need to use javascript to get the variables out of the url, such as:
    > http://www.x.com/test.asp?Dell Computer Corp
    > qs will then end up being "Dell Computer Corp" and I need to make a
    > vbscript variable to also be that so I can query/load/etc certain
    > stuff in asp to display on the site.
    >
    > Thanks for your help!
    >
    > - Jonas
    Comcast, Jul 2, 2003
    #2
    1. Advertising

  3. I don't think it is possible, because the vbscript (the server code) will
    always be executed before the page ever reaches the browser where the
    javascript is executed. Please correct me if I am wrong. I wish someone
    would post a website or write a book on the subject of communication between
    server-side and client-side scripts.

    Phil

    "Jonas Daunoravicius" <> wrote in message
    news:...
    > The subject pretty much sums up what I need to do. Here is what I
    > have so far, but still can't figure out how to get it working:
    >
    > <script language="javascript" type="text/javascript">
    > function fillForm()
    > {
    > // split the query string into pieces
    > var qs = location.search.substr(location.search.indexOf("?")+1);
    > qs = qs.split("&");
    > alert(qs); // qs is the variable that I need to pass into a
    > // vbscript var. This actually works up to here.
    > '<%the_name%>' = qs // this line does not work, but is what I need
    > // to do.
    > }
    > </script>
    >
    >
    > later in the code:
    > <%
    > Response.write ("<script>fillForm();</script>")
    > Response.write("This is the variable: " & the_name)
    > %>
    >
    > On the page it obviously comes up as "This is the variable: " and that
    > is it...blank for the_name.
    >
    > I need to use javascript to get the variables out of the url, such as:
    > http://www.x.com/test.asp?Dell Computer Corp
    > qs will then end up being "Dell Computer Corp" and I need to make a
    > vbscript variable to also be that so I can query/load/etc certain
    > stuff in asp to display on the site.
    >
    > Thanks for your help!
    >
    > - Jonas
    AlwaysLearning, Jul 2, 2003
    #3
  4. I had actually figured out using what you Richard and John mentioned
    yesterday late afternoon. You know how it is when you work on
    something for hours and hours and then all of a sudden you just get it
    to work! :) What you guys said makes sense though and my problem was
    that I didn't know you could do all of that just in vbscript. It even
    ends up being cleaner also. All I ended up doing, just like you guys
    said is:

    <a href=""tier2.asp?prod=" & i & """>" & i & "</a>
    where i is a vbscript variable from a database

    and then in the next page:
    the_name = request.querystring("prod")

    prod has %20 for spaces and the_name just has spaces. It is exactly
    what I was looking for.

    Thanks guys for you input.

    - Jonas
    Jonas Daunoravicius, Jul 2, 2003
    #4
  5. Mike, thanks so much...that is even better now cause now all I needed to do is:

    the_name = Replace(the_name, "%20", " ")

    and I get exactly what I want!

    Thanks for all of your inputs...have a good July 4th.

    - Jonas
    Jonas Daunoravicius, Jul 2, 2003
    #5
  6. Jonas Daunoravicius

    Peter Guest

    Alternatively use the javascript escape function to encode your "&" into a
    %Code. Then unescape it before using it.

    Peter.

    "Jonas Daunoravicius" <> wrote in message
    news:...
    > Mike, thanks so much...that is even better now cause now all I needed to

    do is:
    >
    > the_name = Replace(the_name, "%20", " ")
    >
    > and I get exactly what I want!
    >
    > Thanks for all of your inputs...have a good July 4th.
    >
    > - Jonas
    Peter, Jul 17, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    2
    Views:
    842
    Anthony Judd
    Sep 25, 2004
  2. Jonas Daunoravicius
    Replies:
    5
    Views:
    279
    Peter
    Jul 17, 2003
  3. Katya

    passing javascript to vbscript

    Katya, May 19, 2005, in forum: Javascript
    Replies:
    5
    Views:
    189
    Randy Webb
    May 26, 2005
  4. Replies:
    0
    Views:
    129
  5. balzer

    convert VBScript into Javascript

    balzer, May 13, 2010, in forum: Javascript
    Replies:
    5
    Views:
    979
    Evertjan.
    May 13, 2010
Loading...

Share This Page