Passing a variable from HTLM to Javascript and Back

J

Jim Banks

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','toolbar=no,status=no,menubar=no,location=no,directories=no,resizable=no,scrollbars=yes,width='+ popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);

}


</Script>

</head>

<body>

<a href="javascript:popWindow_D001('Chapter.htm')">Start a chapter in your

area.</a>

</body>

</html>

Thanks in advance.
 
M

McKirahan

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','toolbar=no,status=no,menubar=no,location=no,directories=no,resizable=no,scrollbars=yes,width='+ popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);

}


</Script>

</head>

<body>

<a href="javascript:popWindow_D001('Chapter.htm')">Start 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,directories=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?Chicago')">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.
 
J

Jim Banks

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






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','toolbar=no,status=no,menubar=n
o,location=no,directories=no,resizable=no,scrollbars=yes,width='+
popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);
}
</Script>
</head>
<body>
<a href="javascript:popWindow_D001('Chapter.htm')">Start 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,directories=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?Chicago')">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.
 
M

McKirahan

Jim Banks said:
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






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','toolbar=no,status=no,menubar=n
o,location=no,directories=no,resizable=no,scrollbars=yes,width='+
popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);
}
</Script>
</head>
<body>
<a href="javascript:popWindow_D001('Chapter.htm')">Start 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,directories=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?Chicago')">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.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...
 
J

Jim Banks

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 said:
Jim Banks said:
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






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','toolbar=no,status=no,menubar=n
o,location=no,directories=no,resizable=no,scrollbars=yes,width='+
popwidth+',height='+ popheight+',left='+ popleft+',top='+ poptop);
}
</Script>
</head>
<body>
<a href="javascript:popWindow_D001('Chapter.htm')">Start 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,directories=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?Chicago')">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.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...
 
M

McKirahan

Jim Banks said:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top