By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

Passing a variable from HTLM to Javascript and Back

P: n/a
Greetings

I'm opening a pop up window with a html form, (in one document) and I want to pass a variable to the html form called from the hyperlink.

Here's the code I'm using to pop up the window and call the form. In this particular instance, a city name is what I have to pass to the form Chapter.htm.

<html>

<head>

<Script Language=JavaScript Type="Text/JavaScript">

function PopWindow_D001(url_pop)

{

var popwidth=720;

var popheight=720;

var popleft=100;

var poptop=10;

Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=no,location=no,directorie s=no,resizable=no,scrollbars=yes,width='+ popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);

}
</Script>

</head>

<body>

<a href="javascript:PopWindow_D001('Chapter.htm')">St art a chapter in your

area.</a>

</body>

</html>

Thanks in advance.

--
James Banks
Senior Partner
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Jim Banks" <jb****@ossolution.biz> wrote in message news:4U*********************@news20.bellglobal.com ...
Greetings

I'm opening a pop up window with a html form, (in one document) and I want to pass a variable to the html form called from the hyperlink.

Here's the code I'm using to pop up the window and call the form. In this particular instance, a city name is what I have to pass to the form Chapter.htm.

<html>

<head>

<Script Language=JavaScript Type="Text/JavaScript">

function PopWindow_D001(url_pop)

{

var popwidth=720;

var popheight=720;

var popleft=100;

var poptop=10;

Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=no,location=no,directorie s=no,resizable=no,scrollbars=yes,width='+ popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);

}
</Script>

</head>

<body>

<a href="javascript:PopWindow_D001('Chapter.htm')">St art a chapter in your

area.</a>

</body>

</html>

Thanks in advance.

--
James Banks
Senior Partner

First of all, please post in plain text.

As to your post:

When opening a pop-up you do not have to specify all of the features; if one is set then the reset are assumed to be "no". Thus, omitting your positioning features, "scrollbars=yes" is the same as "toolbar=no,status=no,menubar=no,location=no,direc tories=no,resizable=no,scrollbars=yes"


Below are two pages; watch for word-wrap:

"Chapter.html" (which call "Chapter.htm") follows:

<html>
<head>
<title>Chapter.html</title>
<script type="text/javascript">
function PopWindow_D001(url) {
var popwidth = 720;
var popheight = 720;
var popleft = 100;
var poptop = 10;
var cfg = "scrollbars='yes',width='" + popwidth + "',height='" + popheight + "',left='" + popleft + "',top='" + poptop + "'";
Standard_D001=window.open(url,'standard',cfg);
}
</script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm?Chica go')">Start a chapter in your area.</a>
</body>
</html>

"Chapter.htm" follows:

<html>
<head>
<title>Chapter.htm</title>
<script type="text/javascript">
alert(location.search);
</script>
</head>
<body>
This is "Chapter.htm".
</body>
</html>

"location.search" contains the City name passed along with the preceding "?".

This can be parsed to identify just the City.

If addition parameters are passed they are separated with "&" (an ampersand).

Paramters are often labeled; such as "Chapter.htm?City=Chicago&State=IL".

The name/value pairs are then extracted for use.

Jul 23 '05 #2

P: n/a
Thankyou,

I've captured and displayed the variable in a form without problem. I was
also hoping to use the variable in a html hidden text form field, so I could
save it with other form field data to a file. Is there a way of doing this
as well? As well, I need to capture two variables and am not sure how to
format the alert(location.search); statement to parse out the second
variable.

Much Appreciated

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:Ou0Yc.330288$%_6.94979@attbi_s01...

"Jim Banks" <jb****@ossolution.biz> wrote in message
news:4U*********************@news20.bellglobal.com ...
Greetings
I'm opening a pop up window with a html form, (in one document) and I want
to pass a variable to the html form called from the hyperlink.
Here's the code I'm using to pop up the window and call the form. In this
particular instance, a city name is what I have to pass to the form
Chapter.htm.
<html>
<head>
<Script Language=JavaScript Type="Text/JavaScript">
function PopWindow_D001(url_pop)
{
var popwidth=720;
var popheight=720;
var popleft=100;
var poptop=10;
Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=n
o,location=no,directories=no,resizable=no,scrollba rs=yes,width='+
popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);
}
</Script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm')">St art a chapter in your
area.</a>
</body>
</html>
Thanks in advance.

--
James Banks
Senior Partner

First of all, please post in plain text.

As to your post:

When opening a pop-up you do not have to specify all of the features; if one
is set then the reset are assumed to be "no". Thus, omitting your
positioning features, "scrollbars=yes" is the same as
"toolbar=no,status=no,menubar=no,location=no,direc tories=no,resizable=no,scr
ollbars=yes"


Below are two pages; watch for word-wrap:

"Chapter.html" (which call "Chapter.htm") follows:

<html>
<head>
<title>Chapter.html</title>
<script type="text/javascript">
function PopWindow_D001(url) {
var popwidth = 720;
var popheight = 720;
var popleft = 100;
var poptop = 10;
var cfg = "scrollbars='yes',width='" + popwidth + "',height='" +
popheight + "',left='" + popleft + "',top='" + poptop + "'";
Standard_D001=window.open(url,'standard',cfg);
}
</script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm?Chica go')">Start a chapter
in your area.</a>
</body>
</html>

"Chapter.htm" follows:

<html>
<head>
<title>Chapter.htm</title>
<script type="text/javascript">
alert(location.search);
</script>
</head>
<body>
This is "Chapter.htm".
</body>
</html>

"location.search" contains the City name passed along with the preceding
"?".

This can be parsed to identify just the City.

If addition parameters are passed they are separated with "&" (an
ampersand).

Paramters are often labeled; such as "Chapter.htm?City=Chicago&State=IL".

The name/value pairs are then extracted for use.
Jul 23 '05 #3

P: n/a
"Jim Banks" <jb****@ossolution.biz> wrote in message
news:ia*******************@news20.bellglobal.com.. .
Thankyou,

I've captured and displayed the variable in a form without problem. I was
also hoping to use the variable in a html hidden text form field, so I could save it with other form field data to a file. Is there a way of doing this as well? As well, I need to capture two variables and am not sure how to
format the alert(location.search); statement to parse out the second
variable.

Much Appreciated

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:Ou0Yc.330288$%_6.94979@attbi_s01...

"Jim Banks" <jb****@ossolution.biz> wrote in message
news:4U*********************@news20.bellglobal.com ...
Greetings
I'm opening a pop up window with a html form, (in one document) and I want
to pass a variable to the html form called from the hyperlink.
Here's the code I'm using to pop up the window and call the form. In this
particular instance, a city name is what I have to pass to the form
Chapter.htm.
<html>
<head>
<Script Language=JavaScript Type="Text/JavaScript">
function PopWindow_D001(url_pop)
{
var popwidth=720;
var popheight=720;
var popleft=100;
var poptop=10;
Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=n o,location=no,directories=no,resizable=no,scrollba rs=yes,width='+
popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);
}
</Script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm')">St art a chapter in your
area.</a>
</body>
</html>
Thanks in advance.

--
James Banks
Senior Partner

First of all, please post in plain text.

As to your post:

When opening a pop-up you do not have to specify all of the features; if one is set then the reset are assumed to be "no". Thus, omitting your
positioning features, "scrollbars=yes" is the same as
"toolbar=no,status=no,menubar=no,location=no,direc tories=no,resizable=no,scr ollbars=yes"


Below are two pages; watch for word-wrap:

"Chapter.html" (which call "Chapter.htm") follows:

<html>
<head>
<title>Chapter.html</title>
<script type="text/javascript">
function PopWindow_D001(url) {
var popwidth = 720;
var popheight = 720;
var popleft = 100;
var poptop = 10;
var cfg = "scrollbars='yes',width='" + popwidth + "',height='" +
popheight + "',left='" + popleft + "',top='" + poptop + "'";
Standard_D001=window.open(url,'standard',cfg);
}
</script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm?Chica go')">Start a chapter
in your area.</a>
</body>
</html>

"Chapter.htm" follows:

<html>
<head>
<title>Chapter.htm</title>
<script type="text/javascript">
alert(location.search);
</script>
</head>
<body>
This is "Chapter.htm".
</body>
</html>

"location.search" contains the City name passed along with the preceding
"?".

This can be parsed to identify just the City.

If addition parameters are passed they are separated with "&" (an
ampersand).

Paramters are often labeled; such as "Chapter.htm?City=Chicago&State=IL".

The name/value pairs are then extracted for use.


Save the following as "vars.htm" then call it via
http://{path}/vars.htm?data1=One&data2=Two
<html>
<head>
<title>vars.htm</title>
</head>
<body>
<form name="form1">
<br><input type="text" name="data1">
<br><input type="text" name="data2">
</form>
<script type="text/javascript">
if (location.search != "") {
var parm = location.search.substr(1) + "&";
var pair = parm.split('&');
for (var i=0; i<pair.length-1; i++) {
what = pair[i].split('=');
if (what[0] == "data1") {
document.form1.data1.value = what[1];
} else if (what[0] == "data2") {
document.form1.data2.value = what[1];
}
}
}
</script>
</body>
</html>

Others will probably suggest different/better ways to isolate the name/value
pairs...
Jul 23 '05 #4

P: n/a
McKirahan

Thanks very much, it works greatl. A couple of things, can the code used
to parse the variables be expanded to parse 3 and 4 variables from the
hyperlink? Also, would you be interested in doing some contract custom
programming for me down the road?

James

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:sVKYc.4752$_g7.1558@attbi_s52...
"Jim Banks" <jb****@ossolution.biz> wrote in message
news:ia*******************@news20.bellglobal.com.. .
Thankyou,

I've captured and displayed the variable in a form without problem. I was also hoping to use the variable in a html hidden text form field, so I could
save it with other form field data to a file. Is there a way of doing

this
as well? As well, I need to capture two variables and am not sure how to format the alert(location.search); statement to parse out the second
variable.

Much Appreciated

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:Ou0Yc.330288$%_6.94979@attbi_s01...

"Jim Banks" <jb****@ossolution.biz> wrote in message
news:4U*********************@news20.bellglobal.com ...
Greetings
I'm opening a pop up window with a html form, (in one document) and I want to pass a variable to the html form called from the hyperlink.
Here's the code I'm using to pop up the window and call the form. In this particular instance, a city name is what I have to pass to the form
Chapter.htm.
<html>
<head>
<Script Language=JavaScript Type="Text/JavaScript">
function PopWindow_D001(url_pop)
{
var popwidth=720;
var popheight=720;
var popleft=100;
var poptop=10;

Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=n
o,location=no,directories=no,resizable=no,scrollba rs=yes,width='+
popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);
}
</Script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm')">St art a chapter in your area.</a>
</body>
</html>
Thanks in advance.

--
James Banks
Senior Partner

First of all, please post in plain text.

As to your post:

When opening a pop-up you do not have to specify all of the features; if

one
is set then the reset are assumed to be "no". Thus, omitting your
positioning features, "scrollbars=yes" is the same as

"toolbar=no,status=no,menubar=no,location=no,direc tories=no,resizable=no,scr
ollbars=yes"


Below are two pages; watch for word-wrap:

"Chapter.html" (which call "Chapter.htm") follows:

<html>
<head>
<title>Chapter.html</title>
<script type="text/javascript">
function PopWindow_D001(url) {
var popwidth = 720;
var popheight = 720;
var popleft = 100;
var poptop = 10;
var cfg = "scrollbars='yes',width='" + popwidth + "',height='" +
popheight + "',left='" + popleft + "',top='" + poptop + "'";
Standard_D001=window.open(url,'standard',cfg);
}
</script>
</head>
<body>
<a href="javascript:PopWindow_D001('Chapter.htm?Chica go')">Start a chapter in your area.</a>
</body>
</html>

"Chapter.htm" follows:

<html>
<head>
<title>Chapter.htm</title>
<script type="text/javascript">
alert(location.search);
</script>
</head>
<body>
This is "Chapter.htm".
</body>
</html>

"location.search" contains the City name passed along with the preceding
"?".

This can be parsed to identify just the City.

If addition parameters are passed they are separated with "&" (an
ampersand).

Paramters are often labeled; such as "Chapter.htm?City=Chicago&State=IL".
The name/value pairs are then extracted for use.


Save the following as "vars.htm" then call it via
http://{path}/vars.htm?data1=One&data2=Two
<html>
<head>
<title>vars.htm</title>
</head>
<body>
<form name="form1">
<br><input type="text" name="data1">
<br><input type="text" name="data2">
</form>
<script type="text/javascript">
if (location.search != "") {
var parm = location.search.substr(1) + "&";
var pair = parm.split('&');
for (var i=0; i<pair.length-1; i++) {
what = pair[i].split('=');
if (what[0] == "data1") {
document.form1.data1.value = what[1];
} else if (what[0] == "data2") {
document.form1.data2.value = what[1];
}
}
}
</script>
</body>
</html>

Others will probably suggest different/better ways to isolate the

name/value pairs...

Jul 23 '05 #5

P: n/a
"Jim Banks" <jb****@ossolution.biz> wrote in message
news:Yk********************@news20.bellglobal.com. ..
McKirahan

Thanks very much, it works greatl. A couple of things, can the code used
to parse the variables be expanded to parse 3 and 4 variables from the
hyperlink? Also, would you be interested in doing some contract custom
programming for me down the road?

James


[snip]

The routine handles as many name/value pairs as will fit in a query string
whose limit may be 1024 bytes.

Sure. (BTW, I used to work in Toronto.)
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.