Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript cookies help.

    Hi Guys,

    i kinda need some help on this, what i want to do is click on a button (submit) and take the data form field (document.form1.text1.value) store it in a cookie, opens a window and automatically fills in the new field with the data store in the cookie.

    any help much appreciated.

  • #2
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cmon guys anyone??

  • #3
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    why bother with a cookie for that? also, bumping your own thread just makes it look like someone is already helping you... seems that you would not want that.

    include this code in your main page:
    Code:
     
    var winopen;
    var useVal;
    var isOpen = false;
    var intrvl;
    function openWin(val){
        winopen = window.open("yourpopup.html");
        useVal = val;
        intrvl = setInterval(function(){
                                     if(isOpen){
                                        winopen.document.getElementById("your_field").value = useVal;
                                     }
                                     else
                                         clearInterval(intrvl);
                                    }, 20);
    }
    in your popup, include this code
    Code:
     
    window.onload = function(){window.opener.window["isOpen"] = true;}
    obviously these are both script blocks, so make sure to put them inside script tags, when the window is opened it will then notify the parent window, the parent window will then write the value into the appropriate box in the popup. implementing this on the click of a button would be adding onclick="winOpen(document.getElementById('your_element').value);"
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • Users who have thanked mjlorbet for this post:

    oesxyl (04-29-2008)

  • #4
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if i want it to get data1.value (form1) and input it to the field data2.value (new popup form). how would that be done?
    Quote Originally Posted by mjlorbet View Post
    why bother with a cookie for that? also, bumping your own thread just makes it look like someone is already helping you... seems that you would not want that.

    include this code in your main page:
    Code:
     
    var winopen;
    var useVal;
    var isOpen = false;
    var intrvl;
    function openWin(val){
        winopen = window.open("yourpopup.html");
        useVal = val;
        intrvl = setInterval(function(){
                                     if(isOpen){
                                        winopen.document.getElementById("your_field").value = useVal;
                                     }
                                     else
                                         clearInterval(intrvl);
                                    }, 20);
    }
    in your popup, include this code
    Code:
     
    window.onload = function(){window.opener.window["isOpen"] = true;}
    obviously these are both script blocks, so make sure to put them inside script tags, when the window is opened it will then notify the parent window, the parent window will then write the value into the appropriate box in the popup. implementing this on the click of a button would be adding onclick="winOpen(document.getElementById('your_element').value);"

  • #5
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    Code:
     
    <input type="text" id="data1" />
    <input type="button" onclick="openWin(document.getElementById('data1').value);" />
    then you would change "your_field" in the script i posted to "data2"
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender


  •  

    Posting Permissions

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