PC Review


Reply
Thread Tools Rate Thread

How do I pass information to a page and do something with it.

 
 
Jane Here
Guest
Posts: n/a
 
      27th Nov 2005
I want to go to a page on my web site and show two fields. I will use my own
program to open the web page. I want to pass to the web page the user's name
and their country, and have the web page display this information.

Example: Pass parameters to web site: Jane Here, New York.

Have the web page say: "Welcome Jane Here from New York."

Is the syntax to call the page something like this?

http://www.whatever.com/hello.com?na...eHere?city=New York

I don't know how to capture the variables passed to the page and then how to
use them to show the required text. Can someone get me started please?


 
Reply With Quote
 
 
 
 
clintonG
Guest
Posts: n/a
 
      27th Nov 2005
Almost correct. When there is more than one name=value pair in the
QueryString the second and subsequent pairs are delineated with an ampersand

somewhere.com/example.asp?name=JaneHere&city=New%20York

Note the %20 hex value for a space in the URL. In the target page you can
get the values out of the QueryString using the Request object

Dim name
name = Request.QueryString("name")
Dim city
city = Request.QueryString("city")

Use the Response.Write code blocks to display the values inline...

Hello <%= name %> from <%= city %>.

Finally, you should use web search to learn more about passing values
between pages as there are other methods used for other reasons you'll want
to know how to use.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/


"Jane Here" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I want to go to a page on my web site and show two fields. I will use my
>own program to open the web page. I want to pass to the web page the user's
>name and their country, and have the web page display this information.
>
> Example: Pass parameters to web site: Jane Here, New York.
>
> Have the web page say: "Welcome Jane Here from New York."
>
> Is the syntax to call the page something like this?
>
> http://www.whatever.com/hello.com?na...eHere?city=New York
>
> I don't know how to capture the variables passed to the page and then how
> to use them to show the required text. Can someone get me started please?
>
>



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      28th Nov 2005
Clinton,
Is your code ASP or what?

Jane Here,
I use this javascript code to extract the parameters:
function qsobj(parm)
{var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}

In the HTML, add in the <head> section:
<script type="text/javascript">
var name = qsobj(0) //extracts first parameter
var city = qsobj(1) //extracts second parameter
// add similar lines to extract extra parameters
</script>

The values of "name" and "city" will then be available in any JS used by
this page. It doesn't actually matter what you name the parameters when
passing them. The code in qsobj() doesn't care: the code in the <head>
section renames them.

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

clintonG wrote:
> Almost correct. When there is more than one name=value pair in the
> QueryString the second and subsequent pairs are delineated with an
> ampersand
> somewhere.com/example.asp?name=JaneHere&city=New%20York
>
> Note the %20 hex value for a space in the URL. In the target page you
> can get the values out of the QueryString using the Request object
>
> Dim name
> name = Request.QueryString("name")
> Dim city
> city = Request.QueryString("city")
>
> Use the Response.Write code blocks to display the values inline...
>
> Hello <%= name %> from <%= city %>.
>
> Finally, you should use web search to learn more about passing values
> between pages as there are other methods used for other reasons
> you'll want to know how to use.
>
> <%= Clinton Gallagher
> METROmilwaukee (sm) "A Regional Information Service"
> NET csgallagher AT metromilwaukee.com
> URL http://metromilwaukee.com/
> URL http://clintongallagher.metromilwaukee.com/
>
>
> "Jane Here" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I want to go to a page on my web site and show two fields. I will
>> use my own program to open the web page. I want to pass to the web
>> page the user's name and their country, and have the web page
>> display this information. Example: Pass parameters to web site: Jane
>> Here, New York.
>>
>> Have the web page say: "Welcome Jane Here from New York."
>>
>> Is the syntax to call the page something like this?
>>
>> http://www.whatever.com/hello.com?na...eHere?city=New York
>>
>> I don't know how to capture the variables passed to the page and
>> then how to use them to show the required text. Can someone get me
>> started please?



 
Reply With Quote
 
Jane Here
Guest
Posts: n/a
 
      29th Nov 2005
Thanks for all the answers.

I made a simple html page to show the passed parameters. Can I request more
help to get it to work?
I am calling the page like this:
http://www.somewhere.com/getname.htm...ity=New%20York

and want to say: Hello JaneHere from New York.

Here is the entire code. Can you see what needs correcting?

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Get user name and city</title>
<script type="text/javascript">
var name = qsobj(0) //extracts first parameter
var city = qsobj(1) //extracts second parameter
// add similar lines to extract extra parameters
</script>
</head>

<body>
Hello <%= name %> from <%= city %>.
<p><input type="text" name="name" size="20"></p>
<p><input type="text" name="city" size="20"></p>

<script type="text/javascript">
function qsobj(parm)
{var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}

</script>

</body>
</html>





"Trevor L." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Clinton,
> Is your code ASP or what?
>
> Jane Here,
> I use this javascript code to extract the parameters:
> function qsobj(parm)
> {var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}
>
> In the HTML, add in the <head> section:
> <script type="text/javascript">
> var name = qsobj(0) //extracts first parameter
> var city = qsobj(1) //extracts second parameter
> // add similar lines to extract extra parameters
> </script>
>
> The values of "name" and "city" will then be available in any JS used by
> this page. It doesn't actually matter what you name the parameters when
> passing them. The code in qsobj() doesn't care: the code in the <head>
> section renames them.
>
> --
> Cheers,
> Trevor L.
> Website: http://tandcl.homemail.com.au
>
> clintonG wrote:
>> Almost correct. When there is more than one name=value pair in the
>> QueryString the second and subsequent pairs are delineated with an
>> ampersand
>> somewhere.com/example.asp?name=JaneHere&city=New%20York
>>
>> Note the %20 hex value for a space in the URL. In the target page you
>> can get the values out of the QueryString using the Request object
>>
>> Dim name
>> name = Request.QueryString("name")
>> Dim city
>> city = Request.QueryString("city")
>>
>> Use the Response.Write code blocks to display the values inline...
>>
>> Hello <%= name %> from <%= city %>.
>>
>> Finally, you should use web search to learn more about passing values
>> between pages as there are other methods used for other reasons
>> you'll want to know how to use.
>>
>> <%= Clinton Gallagher
>> METROmilwaukee (sm) "A Regional Information Service"
>> NET csgallagher AT metromilwaukee.com
>> URL http://metromilwaukee.com/
>> URL http://clintongallagher.metromilwaukee.com/
>>
>>
>> "Jane Here" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> I want to go to a page on my web site and show two fields. I will
>>> use my own program to open the web page. I want to pass to the web
>>> page the user's name and their country, and have the web page
>>> display this information. Example: Pass parameters to web site: Jane
>>> Here, New York.
>>>
>>> Have the web page say: "Welcome Jane Here from New York."
>>>
>>> Is the syntax to call the page something like this?
>>>
>>> http://www.whatever.com/hello.com?na...eHere?city=New York
>>>
>>> I don't know how to capture the variables passed to the page and
>>> then how to use them to show the required text. Can someone get me
>>> started please?

>
>



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      29th Nov 2005
Jane Here,
I would do it like this

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Get user name and city</title>
<script type="text/javascript">
function qsobj(parm)
{var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}

var name = qsobj(0) //extracts first parameter
var city = qsobj(1) //extracts second parameter
// add similar lines to extract extra parameters
</script>
</head>

<body>
<script type="text/javascript">
document.write("Hello " + name + " from " + city)
</script>
</body>
</html>

This will write to the page what is between the brackets in document.write

I saved it as test2.html and tested it with
test1.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Get user name and city</title>
</head>
<body>
<a href = "test2.html?name=JaneHere&city=New%20York">Click here </a>
</body>
</html>

This worked fine. Of course you may want format it a bit pretttier.
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Jane Here wrote:
> Thanks for all the answers.
>
> I made a simple html page to show the passed parameters. Can I
> request more help to get it to work?
> I am calling the page like this:
> http://www.somewhere.com/getname.htm...ity=New%20York
>
> and want to say: Hello JaneHere from New York.
>
> Here is the entire code. Can you see what needs correcting?
>


 
Reply With Quote
 
Jane Here
Guest
Posts: n/a
 
      29th Nov 2005
Trevol L

Yes, that works! Excellent.

OK so now I want to go further and add some logic. Using a simple example,
can you show me how to do it?

Say I want to display the country based on the city.
Something like:

if city = "New%20York"
country = "USA"

if city = "London"
country = "UK"

if city = "Paris"
country = "France"


<body>
<script type="text/javascript">
document.write("Hello " + name + " from " + city + " country: " + country)
</script>
</body>
</html>

Jane


"Trevor L." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Jane Here,
> I would do it like this
>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>Get user name and city</title>
> <script type="text/javascript">
> function qsobj(parm)
> {var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}
>
> var name = qsobj(0) //extracts first parameter
> var city = qsobj(1) //extracts second parameter
> // add similar lines to extract extra parameters
> </script>
> </head>
>
> <body>
> <script type="text/javascript">
> document.write("Hello " + name + " from " + city)
> </script>
> </body>
> </html>
>
> This will write to the page what is between the brackets in document.write
>
> I saved it as test2.html and tested it with
> test1.html:
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>Get user name and city</title>
> </head>
> <body>
> <a href = "test2.html?name=JaneHere&city=New%20York">Click here </a>
> </body>
> </html>
>
> This worked fine. Of course you may want format it a bit pretttier.
> --
> Cheers,
> Trevor L.
> Website: http://tandcl.homemail.com.au
>
> Jane Here wrote:
>> Thanks for all the answers.
>>
>> I made a simple html page to show the passed parameters. Can I
>> request more help to get it to work?
>> I am calling the page like this:
>> http://www.somewhere.com/getname.htm...ity=New%20York
>>
>> and want to say: Hello JaneHere from New York.
>>
>> Here is the entire code. Can you see what needs correcting?
>>

>



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      29th Nov 2005
OK Jane,
We're having fun here

You will need some more Javascript.

Your code is nearly correct.
You could code a function
function countryname(city)
{ if city == "New York" country = "USA"
if city == "London" country = "UK"
if city == "Paris" country = "France"
return country}

The only thing a little inefficient about this is that it keeps testing the
value of city even after a match has been found.
To avoid this, you can use "else"
function countryname(city)
{ if city == "New York" country = "USA"
else if city == "London" country = "UK"
else if city == "Paris" country = "France"
.............
else country = "Unknown"
return country}

Another way is the switch statement
function countryname(city)
switch (city)
{
case "New York" : country = "USA"; break
case "London" : country = "UK"; break
case "Paris": country = "France";break
....
default : country = "Unknown"
}
return country}

I like the other way of expressing the if else
variable = (condition1) ? 'value1' : 'value2'
In English this reads: If condition1 is true, then set variable to value1,
else set variable to value2.
The good thing about this is that instead of 'value2', you can add some more
conditions and values. The final value is the default value taken when all
others have been tested
e.g.
variable = (condition1) ? 'value1'
: (condition2) ? 'value2'
: (condition3) ? 'value3'
: 'defaultvalue"

So try this
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Get user name and city</title>
<script type="text/javascript">
function qsobj(parm)
{var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}

function countryname(cityname)
{var country = (cityname = 'New York') ? 'USA'
: (cityname = 'New York') ? 'UK'
: (cityname = 'Paris') ? 'France'
: 'Unknown'
return country}

var name = qsobj(0) //extracts first parameter
var city = qsobj(1) //extracts second parameter
var country = countryname(city) </script>
</head>
<body>
<script type="text/javascript">
document.write("Hello " + name + " from " + city + " country: " + country)
</script>
</body>
</html>

The result of this using the same test1.html was:
Hello JaneHere from New York country: USA

Of course, another embellishment is ask for the name and city in test1.html
and then pass the answers as parameters to test2.html.
That's another story. If you want to do it, I (or many others) can give you
the code.

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Jane Here wrote:
> Trevor L,
> Yes, that works! Excellent.
>
> OK so now I want to go further and add some logic. Using a simple
> example, can you show me how to do it?
>
> Say I want to display the country based on the city.
> Something like:
> if city = "New%20York"
> country = "USA"
> if city = "London"
> country = "UK"
> if city = "Paris"
> country = "France"
>
> <body>
> <script type="text/javascript">
> document.write("Hello " + name + " from " + city + " country: " +
> country) </script>
> </body>
> </html>
>
> Jane



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      29th Nov 2005
Jane
A small error in cutting and pasting the code

The function should be
function countryname(cityname)
{var country = (cityname = 'New York') ? 'USA'
: (cityname = 'London') ? 'UK'
: (cityname = 'Paris') ? 'France'
: 'Unknown'
return country}

Of course, New York still worked, but London would not have ;-(
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


 
Reply With Quote
 
Thomas A. Rowe
Guest
Posts: n/a
 
      29th Nov 2005
Some user may have problem with spaces in the querystring, i.e., New York.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

"Jane Here" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...
> Thanks for all the answers.
>
> I made a simple html page to show the passed parameters. Can I request more help to get it to
> work?
> I am calling the page like this:
> http://www.somewhere.com/getname.htm...ity=New%20York
>
> and want to say: Hello JaneHere from New York.
>
> Here is the entire code. Can you see what needs correcting?
>
> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>Get user name and city</title>
> <script type="text/javascript">
> var name = qsobj(0) //extracts first parameter
> var city = qsobj(1) //extracts second parameter
> // add similar lines to extract extra parameters
> </script>
> </head>
>
> <body>
> Hello <%= name %> from <%= city %>.
> <p><input type="text" name="name" size="20"></p>
> <p><input type="text" name="city" size="20"></p>
>
> <script type="text/javascript">
> function qsobj(parm)
> {var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}
>
> </script>
>
> </body>
> </html>
>
>
>
>
>
> "Trevor L." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Clinton,
>> Is your code ASP or what?
>>
>> Jane Here,
>> I use this javascript code to extract the parameters:
>> function qsobj(parm)
>> {var qpairs = document.location.search.substring(1).split("&")
>> var qvbl = qpairs[parm].split("=")
>> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null}
>>
>> In the HTML, add in the <head> section:
>> <script type="text/javascript">
>> var name = qsobj(0) //extracts first parameter
>> var city = qsobj(1) //extracts second parameter
>> // add similar lines to extract extra parameters
>> </script>
>>
>> The values of "name" and "city" will then be available in any JS used by this page. It doesn't
>> actually matter what you name the parameters when passing them. The code in qsobj() doesn't care:
>> the code in the <head> section renames them.
>>
>> --
>> Cheers,
>> Trevor L.
>> Website: http://tandcl.homemail.com.au
>>
>> clintonG wrote:
>>> Almost correct. When there is more than one name=value pair in the
>>> QueryString the second and subsequent pairs are delineated with an
>>> ampersand
>>> somewhere.com/example.asp?name=JaneHere&city=New%20York
>>>
>>> Note the %20 hex value for a space in the URL. In the target page you
>>> can get the values out of the QueryString using the Request object
>>>
>>> Dim name
>>> name = Request.QueryString("name")
>>> Dim city
>>> city = Request.QueryString("city")
>>>
>>> Use the Response.Write code blocks to display the values inline...
>>>
>>> Hello <%= name %> from <%= city %>.
>>>
>>> Finally, you should use web search to learn more about passing values
>>> between pages as there are other methods used for other reasons
>>> you'll want to know how to use.
>>>
>>> <%= Clinton Gallagher
>>> METROmilwaukee (sm) "A Regional Information Service"
>>> NET csgallagher AT metromilwaukee.com
>>> URL http://metromilwaukee.com/
>>> URL http://clintongallagher.metromilwaukee.com/
>>>
>>>
>>> "Jane Here" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> I want to go to a page on my web site and show two fields. I will
>>>> use my own program to open the web page. I want to pass to the web
>>>> page the user's name and their country, and have the web page
>>>> display this information. Example: Pass parameters to web site: Jane Here, New York.
>>>>
>>>> Have the web page say: "Welcome Jane Here from New York."
>>>>
>>>> Is the syntax to call the page something like this?
>>>>
>>>> http://www.whatever.com/hello.com?na...eHere?city=New York
>>>>
>>>> I don't know how to capture the variables passed to the page and
>>>> then how to use them to show the required text. Can someone get me
>>>> started please?

>>
>>

>
>



 
Reply With Quote
 
Jane Here
Guest
Posts: n/a
 
      29th Nov 2005
Hi Trevor

Thanks.
Whatever info I enter, it gives me country: USA
Hello JaneHere from London country: USA

It is here:
http://www.usbdial.com/get2.htm?name...re&city=London

I also tried the elseif function but that didn't return anything:
http://www.usbdial.com/get1.htm?name...re&city=London

I then tried the switch function but that didn't return anything:
http://www.usbdial.com/get3.htm?name...re&city=London

Can you see what I am doing wrong?

Jane

"Trevor L." <(E-Mail Removed)> wrote in message
news:u%(E-Mail Removed)...
> Jane
> A small error in cutting and pasting the code
>
> The function should be
> function countryname(cityname)
> {var country = (cityname = 'New York') ? 'USA'
> : (cityname = 'London') ? 'UK'
> : (cityname = 'Paris') ? 'France'
> : 'Unknown'
> return country}
>
> Of course, New York still worked, but London would not have ;-(
> --
> Cheers,
> Trevor L.
> Website: http://tandcl.homemail.com.au
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass Information between two different windows czuvich Microsoft ASP .NET 1 30th Dec 2006 10:01 AM
Pass information from XML file to ASPX page evangelous@gmail.com Microsoft ASP .NET 1 22nd Jul 2005 12:52 PM
Best way to pass information between pages? hugo.flores@ge.com Microsoft ASP .NET 3 17th Jun 2005 03:40 PM
Need to pass information into a web page. =?Utf-8?B?UGF1bA==?= Microsoft ASP .NET 9 16th Jul 2004 01:23 AM
Best way to pass information (recordset) from VB 6.0 dll to C# Andrew Mueller Microsoft C# .NET 0 17th Jul 2003 08:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:18 PM.