passing form variable to a second page

Discussion in 'JavaScript' started by borojim, Jan 30, 2009.

  1. #1
    OMG! why can I not get this simplwe thing to work!!!!

    I am really rusty when It comes to Javascript so when you point out the opbvious answer I will post my address so you can come round and slap me for being an idiot!

    okay I have a few pages and when I enter a manual value for the variable everything else works, except I cannot pass the value automatically from the first page to the next!

    simpley put here is the first page:

    Parent HTML:
    <body>
    <script type="text/javascript">
    var passed = 0
    </script>
    <form method="get" action="child.html">
    <p> Please enter how many blocks you have completed: 
    <input name="blknumb" id="blknumb" type="text" size="25">
    <input type="hidden" name="passed" id="passed" value="0"
    <input  type="submit" value="Submit"/>
    </p>
    </form>
    </body>
    Code (markup):
    and here is the page to be passed to:

    child.html (this is just the section that recieves the value and displays it for debuggin to show the value has been passed)
    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript">
    var frmout;
    frmout = document.forms[blknumb];
    
    document.write(frmout);
    </script>
    </body>
    Code (markup):
    As far as I can see, the variable 'blknumb' should be sent to child.html and displayed, what actually happens Is I get 'null' returned no matter what value I put in!

    Please let me know what I am doing wrong so I can oil up the rusty bits!

    Jimmy
     
    borojim, Jan 30, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    look at 'similar' threads at the bottom - MMJ just replied to another one by giving a function that captures get variables in a way similar to $_GET in php...
     
    dimitar christoff, Jan 30, 2009 IP
  3. borojim

    borojim Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks will look at it
     
    borojim, Jan 30, 2009 IP
  4. JDOMPer

    JDOMPer Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    There is a simple way to transfer a small amount of date using the window name attribute

    SEND
    function loaddata(){
    window.name= "Data to be transferred"
    mynew="window.location= 'URL of second page'"
    eval(mynew)
    }

    RECEIVE
    you need a function that loads at the start on the page

    function startme() {
    //get data from window.name attribute
    mytown=window.name
    //set window name to blank to stop future use
    window.name = ""
    // test if the name is not blank and load it into the new form
    // blah blah
    }

    Its simple and works well.
    I can provide further details and options if you want to go this way.

    Cheers
     
    JDOMPer, Jan 30, 2009 IP
  5. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #5
    It looks to me that "frmout = document.forms[blknumb];" is capturing info on the child page and not the parent page.
     
    mmerlinn, Jan 31, 2009 IP
  6. borojim

    borojim Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks JDOMPer and mmerlinn!

    I will give the window one a shot, It looks to me like the one I could use, but to be honest, I may need to pass more than one variable, I know there is a way but I cannot remember how to do it, it got to do with the 'action=""' part and you can use it when validating forms (by sending the form data to a script in another page to be validated.)

    I will keep trying!

    Jimmy
     
    borojim, Jan 31, 2009 IP
  7. JDOMPer

    JDOMPer Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    For several simple word transfers you can simply use

    http://www.sendtourl.html?var1=name&var2=address etc.

    for more complicated transfers

    See http://forums.digitalpoint.com/showthread.php?p=8319260#post8319260

    You don't need to use a database. This simplifies data transfers.

    Cheers
     
    JDOMPer, Jan 31, 2009 IP
  8. JDOMPer

    JDOMPer Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    '?' + multiple variables added to the url separated by '&'

    http://www.google.com/search?hl=en&rls=com.microsoft:en-us:IE-SearchBox&q=tagalong%20tours%20in%20outback%20australia&start=10&sa=N
     
    JDOMPer, Jan 31, 2009 IP