473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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:
http://www.x.com/test.asp?Dell%20Computer%20Corp
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
Jul 19 '05 #1
7 72084
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" <Jd************@questarcapital.com> wrote in message
news:fa*************************@posting.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:
http://www.x.com/test.asp?Dell%20Computer%20Corp
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

Jul 19 '05 #2
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" <Jd************@questarcapital.com> wrote in message
news:fa*************************@posting.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:
http://www.x.com/test.asp?Dell%20Computer%20Corp
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

Jul 19 '05 #3
But surely if you are using ASP you can do the following:

URL : http://www.testsite.com/test.asp?Com...omputer%20Corp

<% 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 = document.plform.elements.length;
do {
if (document.plform[EleNum].type == "select-one") {
if (document.plform[EleNum].selectedIndex != 0) {
NewURL += document.plform[EleNum].name + "=" +
document.plform[EleNum].value + "&";
}
}
if(document.plform[EleNum].type == "text") {
if (document.plform[EleNum].value != 0 ) {
NewURL += document.plform[EleNum].name + "=" +
document.plform[EleNum].value + "&";
}
}
if(document.plform[EleNum].type == "textarea") {
if (document.plform[EleNum].value != 0 ) {
NewURL += document.plform[EleNum].name + "=" +
document.plform[EleNum].value + "&";
}
}
} while(++EleNum < EleNumMx);
window.location=NewURL;

Hope this helps

John Dobson

"AlwaysLearning" <ru****@nwlink.com> wrote in message
news:tM*****************@rwcrnsc52.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" <Jd************@questarcapital.com> wrote in message
news:fa*************************@posting.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:
http://www.x.com/test.asp?Dell%20Computer%20Corp
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


Jul 19 '05 #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
Jul 19 '05 #5
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 www.oscorp.com
"Jonas Daunoravicius" <Jd************@questarcapital.com> wrote in message
news:fa**************************@posting.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

Jul 19 '05 #6
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
Jul 19 '05 #7
Alternatively use the javascript escape function to encode your "&" into a
%Code. Then unescape it before using it.

Peter.

"Jonas Daunoravicius" <Jd************@questarcapital.com> wrote in message
news:fa**************************@posting.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

Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Patrice | last post by:
Hi, I'm trying to use a javascript function passing a vb variable. I don't understand why it doesn't work. Can someone help me? Thanks in advance. Here is my javascript function used to...
1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
6
by: | last post by:
I have MyEnumeratedSet { ... some values go here ... } I have a variable that is defined as MyEnumeratedSet MyVariable; I have a function that needs to be able to set a variable by Ref...
1
by: Machi | last post by:
let say i have a web form with a button on it ... when i click the button, it will pop up one small window to allow me to save a pdf file, everything is done using code behind as below ... however,...
0
by: csgraham74 | last post by:
Hi guys, I am writing an application in asp.net but im attempting to write some client side validation. I have most of this working but i am having trouble reading cookies set in asp.net using...
0
by: neon123 | last post by:
i am using a sql loader to load data into oracle 8. i am using vbscript to run the sql loader. i need to pass username and password entered through vbscript ,,into the visual basic application . ...
3
by: TheLymner | last post by:
I have, what I believe, is a rather simple question. However, I cannot find the answer anywhere on the web nor in any of the library of xml or javascript/asp books available. How do I pass and store...
5
by: meenu_susi | last post by:
hi all Could you please help me out i creating folder using vbscript.. I have used the following code... <SCRIPT LANGUAGE="VBScript"> <!-- Option Explicit
5
Soniad
by: Soniad | last post by:
Hello, I want to include asp file within vbscript, this file name i am taking in variable . and when i use this variable in the include tag outside delimiters(<%%>), it does not work, <%Dim...
5
by: asdasd10 | last post by:
It is possible create Seasson variable (ASP) through VBscript?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.