Professional Web Applications Themes

passing javascript variable into asp variable using vbscript - ASP

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 ...

  1. #1

    Default passing javascript variable into asp variable using vbscript

    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:
    [url]http://www.x.com/test.asp?Dell%20Computer%20Corp[/url]
    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 Guest

  2. #2

    Default Re: passing javascript variable into asp variable using vbscript

    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" <Jdaunoraviciusquestarcapital.com> wrote in message
    news:fab603b3.0307010956.594dd73posting.google.co m...
    > 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:
    > [url]http://www.x.com/test.asp?Dell%20Computer%20Corp[/url]
    > 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 Guest

  3. #3

    Default Re: passing javascript variable into asp variable using vbscript

    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" <Jdaunoraviciusquestarcapital.com> wrote in message
    news:fab603b3.0307010956.594dd73posting.google.co m...
    > 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:
    > [url]http://www.x.com/test.asp?Dell%20Computer%20Corp[/url]
    > 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 Guest

  4. #4

    Default Re: passing javascript variable into asp variable using vbscript

    But surely if you are using ASP you can do the following:

    URL : [url]www.testsite.com/test.asp?Company=Dell%20Computer%20Corp[/url]

    <% varCompany = Request.QueryString("Company") %>
    to extract from the URL to variable varCompany

    and where you need to place the variable:

    <%= varCompany %>

    all in ASP


    The only bit using VB of Javascript is the creation of the URL (which here I
    am creating from items in a form, in the case of someone NOT using the
    submit button!) And then reloading the page.

    NewURL = "location.asp?";
    var EleNum = 0;
    var EleNumMx = doent.plform.elements.length;
    do {
    if (doent.plform[EleNum].type == "select-one") {
    if (doent.plform[EleNum].selectedIndex != 0) {
    NewURL += doent.plform[EleNum].name + "=" +
    doent.plform[EleNum].value + "&";
    }
    }
    if(doent.plform[EleNum].type == "text") {
    if (doent.plform[EleNum].value != 0 ) {
    NewURL += doent.plform[EleNum].name + "=" +
    doent.plform[EleNum].value + "&";
    }
    }
    if(doent.plform[EleNum].type == "textarea") {
    if (doent.plform[EleNum].value != 0 ) {
    NewURL += doent.plform[EleNum].name + "=" +
    doent.plform[EleNum].value + "&";
    }
    }
    } while(++EleNum < EleNumMx);
    window.location=NewURL;

    Hope this helps

    John Dobson



    "AlwaysLearning" <rudmannwlink.com> wrote in message
    news:tMtMa.1353$a45.3325rwcrnsc52.ops.asp.att.net ...
    > 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" <Jdaunoraviciusquestarcapital.com> wrote in message
    > news:fab603b3.0307010956.594dd73posting.google.co m...
    > > 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:
    > > [url]http://www.x.com/test.asp?Dell%20Computer%20Corp[/url]
    > > 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
    >
    >

    John D Guest

  5. #5

    Default Re: passing javascript variable into asp variable using vbscript

    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 Guest

  6. #6

    Default Re: passing javascript variable into asp variable using vbscript

    To get the whole query string:

    <%
    the_name = Request.QueryString()
    %>

    You can pass it to client but not the other way around:

    <script language="javascript">
    var the_name = ""
    </script>
    <%
    Dim the_name
    the_name = Request.QueryString()
    Response.write("the name is " & the_name)
    Response.write("<script>the_name=""" & the_name & """;</script>")
    %>
    <script language="javascript">
    alert(the_name)
    </script>

    --
    Mike S.
    Optimal Systems [url]www.oscorp.com[/url]
    "Jonas Daunoravicius" <Jdaunoraviciusquestarcapital.com> wrote in message
    news:fab603b3.0307020702.7df8944eposting.google.c om...
    > I just noticed that if "&" is passed, after you do a querysting, it
    > drops everything passed the "&" even though vbscript variables can
    > hold & inside.
    >
    > For instance, if the URL is www.x.asp/?prod="dell%20&%20ibm"
    > then if you do this on the next page:
    > the_name = request.querystring("prod")
    > it will only come up as "dell" instead of "dell & ibm"
    >
    > Everything else seems to work fine, but this. Anyone have a
    > suggestion in how to avoid this?
    >
    > Thanks
    >
    > - Jonas
    >

    Mike S. Guest

  7. #7

    Default Re: passing javascript variable into asp variable using vbscript

    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 Guest

  8. #8

    Default Re: passing javascript variable into asp variable using vbscript

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

    Peter.

    "Jonas Daunoravicius" <Jdaunoraviciusquestarcapital.com> wrote in message
    news:fab603b3.0307021259.72c20f86posting.google.c om...
    > 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 Guest

Similar Threads

  1. passing variable to javascript pop-up window
    By jr_serrano in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: July 6th, 08:55 PM
  2. Passing a variable
    By Angie2099 in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: June 26th, 02:33 PM
  3. Javascript variable to CF Variable?
    By Frank D'Elia in forum Macromedia ColdFusion
    Replies: 1
    Last Post: June 3rd, 04:35 PM
  4. URL Variable Passing
    By DManson in forum Macromedia ColdFusion
    Replies: 0
    Last Post: April 27th, 03:18 PM
  5. Reference a VBScript Variable in ASP
    By BP Prgm in forum ASP
    Replies: 4
    Last Post: July 31st, 01:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139