Passing a variable from HTLM to Javascript and Back | | |
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 | | | | re: Passing a variable from HTLM to Javascript and Back
"Jim Banks" <jbanks@ossolution.biz> wrote in message news:4U%Xc.26137$_H5.1004026@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. | | | | re: Passing a variable from HTLM to Javascript and Back
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" <News@McKirahan.com> wrote in message
news:Ou0Yc.330288$%_6.94979@attbi_s01...
"Jim Banks" <jbanks@ossolution.biz> wrote in message
news:4U%Xc.26137$_H5.1004026@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. | | | | re: Passing a variable from HTLM to Javascript and Back
"Jim Banks" <jbanks@ossolution.biz> wrote in message
news:iaJYc.8049$CG3.500302@news20.bellglobal.com.. .[color=blue]
> 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[/color]
could[color=blue]
> save it with other form field data to a file. Is there a way of doing[/color]
this[color=blue]
> 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" <News@McKirahan.com> wrote in message
> news:Ou0Yc.330288$%_6.94979@attbi_s01...
>
> "Jim Banks" <jbanks@ossolution.biz> wrote in message
> news:4U%Xc.26137$_H5.1004026@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;
>[/color]
Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=n[color=blue]
> 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[/color]
one[color=blue]
> is set then the reset are assumed to be "no". Thus, omitting your
> positioning features, "scrollbars=yes" is the same as
>[/color]
"toolbar=no,status=no,menubar=no,location=no,direc tories=no,resizable=no,scr[color=blue]
> 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.
>
>[/color]
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... | | | | re: Passing a variable from HTLM to Javascript and Back
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" <News@McKirahan.com> wrote in message
news:sVKYc.4752$_g7.1558@attbi_s52...[color=blue]
> "Jim Banks" <jbanks@ossolution.biz> wrote in message
> news:iaJYc.8049$CG3.500302@news20.bellglobal.com.. .[color=green]
> > Thankyou,
> >
> > I've captured and displayed the variable in a form without problem. I[/color][/color]
was[color=blue][color=green]
> > also hoping to use the variable in a html hidden text form field, so I[/color]
> could[color=green]
> > save it with other form field data to a file. Is there a way of doing[/color]
> this[color=green]
> > as well? As well, I need to capture two variables and am not sure how[/color][/color]
to[color=blue][color=green]
> > format the alert(location.search); statement to parse out the second
> > variable.
> >
> > Much Appreciated
> >
> >
> >
> >
> >
> > "McKirahan" <News@McKirahan.com> wrote in message
> > news:Ou0Yc.330288$%_6.94979@attbi_s01...
> >
> > "Jim Banks" <jbanks@ossolution.biz> wrote in message
> > news:4U%Xc.26137$_H5.1004026@news20.bellglobal.com ...
> > Greetings
> > I'm opening a pop up window with a html form, (in one document) and I[/color][/color]
want[color=blue][color=green]
> > 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[/color][/color]
this[color=blue][color=green]
> > 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;
> >[/color]
>[/color]
Standard_D001=window.open(url_pop,'standard','tool bar=no,status=no,menubar=n[color=blue][color=green]
> > 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[/color][/color]
your[color=blue][color=green]
> > 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[/color]
> one[color=green]
> > is set then the reset are assumed to be "no". Thus, omitting your
> > positioning features, "scrollbars=yes" is the same as
> >[/color]
>[/color]
"toolbar=no,status=no,menubar=no,location=no,direc tories=no,resizable=no,scr[color=blue][color=green]
> > 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[/color][/color]
chapter[color=blue][color=green]
> > 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[/color][/color]
"Chapter.htm?City=Chicago&State=IL".[color=blue][color=green]
> >
> > The name/value pairs are then extracted for use.
> >
> >[/color]
>
> 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[/color]
name/value[color=blue]
> pairs...
>
>[/color] | | | | re: Passing a variable from HTLM to Javascript and Back
"Jim Banks" <jbanks@ossolution.biz> wrote in message
news:Yk3Zc.13971$CG3.841004@news20.bellglobal.com. ..[color=blue]
> 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[/color]
[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.) |  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,537 network members.
|