How do I display textbox data from one html page in another one.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BobQuinn
    New Member
    • Feb 2010
    • 7

    #1

    How do I display textbox data from one html page in another one.

    I have a problem that seems like it should be easy, yet I don't quite have the answer. I have an html page with a number of textboxes for input. When the user clicks a button, a javascript routine performs calculations and displays the output. This works fine. I'm using a button to create a "printer friendly" version of the output in a new html page. I'm trying to access the calculated values and put them in textboxes on the new form without luck.

    Say Page1.htm is displaying the output with a button for the printer friendly page (Page2.htm). In my javascript for Page2.htm I have in initPage2 function that is called from the onload of Page2. I'm using one javascript file for both Page1.htm and Page2.htm (Page.js). My code looks something like this:

    Code:
    function initPage2() {
      document.Page2.txtTest2.value=document.getElementsByName('txtTest1').value;  // Doesn't work, but
        document.Page2.txtTest2.value="99";  // Works fine
    }
    What's wrong with the getElementsByNa me?
    Any suggestions would be appreciated!
    Bob
    Last edited by gits; Apr 16 '10, 04:37 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    document.getEle mentsByName() returns a nodelist ... so probably it should look like:

    Code:
    document.getElementsByName('txtTest1')[0].value
    you need to refer to a specific node.

    kind regards

    Comment

    • BobQuinn
      New Member
      • Feb 2010
      • 7

      #3
      I tried adding the [0] but I get the yellow triange with the exclamation mark.
      If I have two html pages and each one references to the same js page, does the second page that loads wipe out variables created from the first page?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        are you using frames? or what do you mean with 2 pages? or are they loaded sequentially? the second page cannot access variables from the first page then ... they are lost onload of a new page ... you would need to pass the values to the second page ...

        Comment

        • BobQuinn
          New Member
          • Feb 2010
          • 7

          #5
          OK... I think I found a method that works. If I write the textbox data to a session cookie, then read the cookie in the new page I have my data.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            that is one option ... you could even pass it through the url as a querystring and read it from there ...

            kind regards

            Comment

            Working...