Passing a variable from HTLM to Javascript and Back

Discussion in 'Javascript' started by Jim Banks, Aug 28, 2004.

  1. Jim Banks

    Jim Banks Guest

    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
     
    Jim Banks, Aug 28, 2004
    #1
    1. Advertising

  2. Jim Banks

    McKirahan Guest

    "Jim Banks" <> wrote in message news:4U%Xc.26137$...
    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.
     
    McKirahan, Aug 28, 2004
    #2
    1. Advertising

  3. Jim Banks

    Jim Banks Guest

    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" <> wrote in message
    news:Ou0Yc.330288$%_6.94979@attbi_s01...

    "Jim Banks" <> wrote in message
    news:4U%Xc.26137$...
    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.
     
    Jim Banks, Aug 30, 2004
    #3
  4. Jim Banks

    McKirahan Guest

    "Jim Banks" <> wrote in message
    news:iaJYc.8049$...
    > 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" <> wrote in message
    > news:Ou0Yc.330288$%_6.94979@attbi_s01...
    >
    > "Jim Banks" <> wrote in message
    > news:4U%Xc.26137$...
    > 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...
     
    McKirahan, Aug 30, 2004
    #4
  5. Jim Banks

    Jim Banks Guest

    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" <> wrote in message
    news:sVKYc.4752$_g7.1558@attbi_s52...
    > "Jim Banks" <> wrote in message
    > news:iaJYc.8049$...
    > > 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" <> wrote in message
    > > news:Ou0Yc.330288$%_6.94979@attbi_s01...
    > >
    > > "Jim Banks" <> wrote in message
    > > news:4U%Xc.26137$...
    > > 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...
    >
    >
     
    Jim Banks, Aug 31, 2004
    #5
  6. Jim Banks

    McKirahan Guest

    "Jim Banks" <> wrote in message
    news:Yk3Zc.13971$...
    > 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.)
     
    McKirahan, Sep 1, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shil
    Replies:
    2
    Views:
    2,050
    Eliyahu Goldin
    Jan 2, 2007
  2. Jonas Daunoravicius
    Replies:
    5
    Views:
    325
    Peter
    Jul 17, 2003
  3. Steve Cosh
    Replies:
    1
    Views:
    169
    joewiii
    Nov 18, 2005
  4. James Dinkel
    Replies:
    5
    Views:
    88
    James Dinkel
    Aug 20, 2008
  5. Jonas Daunoravicius
    Replies:
    5
    Views:
    295
    Peter
    Jul 17, 2003
Loading...

Share This Page