Passing a variable from HTLM to Javascript and Back

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Banks

    #1

    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=JavaSc ript Type="Text/JavaScript">

    function PopWindow_D001( url_pop)

    {

    var popwidth=720;

    var popheight=720;

    var popleft=100;

    var poptop=10;

    Standard_D001=w indow.open(url_ pop,'standard', 'toolbar=no,sta tus=no,menubar= no,location=no, directories=no, resizable=no,sc rollbars=yes,wi dth='+ popwidth+',heig ht='+ popheight+',lef t='+ popleft+',top=' + poptop);

    }


    </Script>

    </head>

    <body>

    <a href="javascrip t:PopWindow_D00 1('Chapter.htm' )">Start a chapter in your

    area.</a>

    </body>

    </html>

    Thanks in advance.

    --
    James Banks
    Senior Partner
  • McKirahan

    #2
    Re: Passing a variable from HTLM to Javascript and Back


    "Jim Banks" <jbanks@ossolut ion.biz> wrote in message news:4U%Xc.2613 7$_H5.1004026@n ews20.bellgloba l.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=JavaSc ript Type="Text/JavaScript">

    function PopWindow_D001( url_pop)

    {

    var popwidth=720;

    var popheight=720;

    var popleft=100;

    var poptop=10;

    Standard_D001=w indow.open(url_ pop,'standard', 'toolbar=no,sta tus=no,menubar= no,location=no, directories=no, resizable=no,sc rollbars=yes,wi dth='+ popwidth+',heig ht='+ popheight+',lef t='+ popleft+',top=' + poptop);

    }


    </Script>

    </head>

    <body>

    <a href="javascrip t:PopWindow_D00 1('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,sta tus=no,menubar= no,location=no, directories=no, resizable=no,sc rollbars=yes"




    Below are two pages; watch for word-wrap:

    "Chapter.ht ml" (which call "Chapter.ht m") 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='ye s',width='" + popwidth + "',height=' " + popheight + "',left='" + popleft + "',top='" + poptop + "'";
    Standard_D001=w indow.open(url, 'standard',cfg) ;
    }
    </script>
    </head>
    <body>
    <a href="javascrip t:PopWindow_D00 1('Chapter.htm? Chicago')">Star t a chapter in your area.</a>
    </body>
    </html>

    "Chapter.ht m" follows:

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

    "location.searc h" 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?Ci ty=Chicago&Stat e=IL".

    The name/value pairs are then extracted for use.

    Comment

    • Jim Banks

      #3
      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.3302 88$%_6.94979@at tbi_s01...

      "Jim Banks" <jbanks@ossolut ion.biz> wrote in message
      news:4U%Xc.2613 7$_H5.1004026@n ews20.bellgloba l.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=JavaSc ript Type="Text/JavaScript">
      function PopWindow_D001( url_pop)
      {
      var popwidth=720;
      var popheight=720;
      var popleft=100;
      var poptop=10;
      Standard_D001=w indow.open(url_ pop,'standard', 'toolbar=no,sta tus=no,menubar= n
      o,location=no,d irectories=no,r esizable=no,scr ollbars=yes,wid th='+
      popwidth+',heig ht='+ popheight+',lef t='+ popleft+',top=' + poptop);
      }
      </Script>
      </head>
      <body>
      <a href="javascrip t:PopWindow_D00 1('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,sta tus=no,menubar= no,location=no, directories=no, resizable=no,sc r
      ollbars=yes"




      Below are two pages; watch for word-wrap:

      "Chapter.ht ml" (which call "Chapter.ht m") 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='ye s',width='" + popwidth + "',height=' " +
      popheight + "',left='" + popleft + "',top='" + poptop + "'";
      Standard_D001=w indow.open(url, 'standard',cfg) ;
      }
      </script>
      </head>
      <body>
      <a href="javascrip t:PopWindow_D00 1('Chapter.htm? Chicago')">Star t a chapter
      in your area.</a>
      </body>
      </html>

      "Chapter.ht m" follows:

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

      "location.searc h" 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?Ci ty=Chicago&Stat e=IL".

      The name/value pairs are then extracted for use.


      Comment

      • McKirahan

        #4
        Re: Passing a variable from HTLM to Javascript and Back

        "Jim Banks" <jbanks@ossolut ion.biz> wrote in message
        news:iaJYc.8049 $CG3.500302@new s20.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.3302 88$%_6.94979@at tbi_s01...
        >
        > "Jim Banks" <jbanks@ossolut ion.biz> wrote in message
        > news:4U%Xc.2613 7$_H5.1004026@n ews20.bellgloba l.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=JavaSc ript Type="Text/JavaScript">
        > function PopWindow_D001( url_pop)
        > {
        > var popwidth=720;
        > var popheight=720;
        > var popleft=100;
        > var poptop=10;
        >[/color]
        Standard_D001=w indow.open(url_ pop,'standard', 'toolbar=no,sta tus=no,menubar= n[color=blue]
        > o,location=no,d irectories=no,r esizable=no,scr ollbars=yes,wid th='+
        > popwidth+',heig ht='+ popheight+',lef t='+ popleft+',top=' + poptop);
        > }
        > </Script>
        > </head>
        > <body>
        > <a href="javascrip t:PopWindow_D00 1('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[/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,sta tus=no,menubar= no,location=no, directories=no, resizable=no,sc r[color=blue]
        > ollbars=yes"
        >
        >
        >
        >
        > Below are two pages; watch for word-wrap:
        >
        > "Chapter.ht ml" (which call "Chapter.ht m") 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='ye s',width='" + popwidth + "',height=' " +
        > popheight + "',left='" + popleft + "',top='" + poptop + "'";
        > Standard_D001=w indow.open(url, 'standard',cfg) ;
        > }
        > </script>
        > </head>
        > <body>
        > <a href="javascrip t:PopWindow_D00 1('Chapter.htm? Chicago')">Star t a chapter
        > in your area.</a>
        > </body>
        > </html>
        >
        > "Chapter.ht m" follows:
        >
        > <html>
        > <head>
        > <title>Chapter. htm</title>
        > <script type="text/javascript">
        > alert(location. search);
        > </script>
        > </head>
        > <body>
        > This is "Chapter.ht m".
        > </body>
        > </html>
        >
        > "location.searc h" 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?Ci ty=Chicago&Stat e=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.searc h != "") {
        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...


        Comment

        • Jim Banks

          #5
          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@ossolut ion.biz> wrote in message
          > news:iaJYc.8049 $CG3.500302@new s20.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.3302 88$%_6.94979@at tbi_s01...
          > >
          > > "Jim Banks" <jbanks@ossolut ion.biz> wrote in message
          > > news:4U%Xc.2613 7$_H5.1004026@n ews20.bellgloba l.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=JavaSc ript Type="Text/JavaScript">
          > > function PopWindow_D001( url_pop)
          > > {
          > > var popwidth=720;
          > > var popheight=720;
          > > var popleft=100;
          > > var poptop=10;
          > >[/color]
          >[/color]
          Standard_D001=w indow.open(url_ pop,'standard', 'toolbar=no,sta tus=no,menubar= n[color=blue][color=green]
          > > o,location=no,d irectories=no,r esizable=no,scr ollbars=yes,wid th='+
          > > popwidth+',heig ht='+ popheight+',lef t='+ popleft+',top=' + poptop);
          > > }
          > > </Script>
          > > </head>
          > > <body>
          > > <a href="javascrip t:PopWindow_D00 1('Chapter.htm' )">Start 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,sta tus=no,menubar= no,location=no, directories=no, resizable=no,sc r[color=blue][color=green]
          > > ollbars=yes"
          > >
          > >
          > >
          > >
          > > Below are two pages; watch for word-wrap:
          > >
          > > "Chapter.ht ml" (which call "Chapter.ht m") 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='ye s',width='" + popwidth + "',height=' " +
          > > popheight + "',left='" + popleft + "',top='" + poptop + "'";
          > > Standard_D001=w indow.open(url, 'standard',cfg) ;
          > > }
          > > </script>
          > > </head>
          > > <body>
          > > <a href="javascrip t:PopWindow_D00 1('Chapter.htm? Chicago')">Star t a[/color][/color]
          chapter[color=blue][color=green]
          > > in your area.</a>
          > > </body>
          > > </html>
          > >
          > > "Chapter.ht m" follows:
          > >
          > > <html>
          > > <head>
          > > <title>Chapter. htm</title>
          > > <script type="text/javascript">
          > > alert(location. search);
          > > </script>
          > > </head>
          > > <body>
          > > This is "Chapter.ht m".
          > > </body>
          > > </html>
          > >
          > > "location.searc h" 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?Ci ty=Chicago&Stat e=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.searc h != "") {
          > 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]


          Comment

          • McKirahan

            #6
            Re: Passing a variable from HTLM to Javascript and Back

            "Jim Banks" <jbanks@ossolut ion.biz> wrote in message
            news:Yk3Zc.1397 1$CG3.841004@ne ws20.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.)


            Comment

            Working...