SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Albany, N.Y.
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    populate text box from popup windows text box

    I want to create a script that will open another html page, I currently use the following code to accomplish this task

    HTML code:

    Code:
    <input type="text"  name="test" onclick="opentime()" />
    External JS file code:

    Code:
    function opentime()
    {
    window.open("TimeAMPM.htm","Time", "width=175, height=15, scrollbars=no, titlebar=no status=no location=no");
    }
    I want to add a parameter to opentime() that will be the name of the "input type=text" so that I can pass a value to the text box from store in another text box on the html doc it opened. Is there a sample code of this are does someone have any ideas how to get started? simple example will do it's my first week with javascript.

    thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    You can pass the value as a part of the querystring. Multiple variables are separated by an & symbol, or from HTML, &amp;

    Code HTML4Strict:
    window.open("TimeAMPM.htm?variable=value&amp;variable2=value2",....

    Then on the other end you can get it with javascript.

    Code JavaScript:
    var variable = getQueryVariable('variable');
     
    function getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      } 
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •