...

View Full Version : javascript cookies help.



ibbz101
04-28-2008, 03:44 PM
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.

ibbz101
04-29-2008, 12:11 AM
cmon guys anyone??

mjlorbet
04-29-2008, 12:21 AM
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:


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


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);"

ibbz101
04-29-2008, 02:11 AM
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?

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:


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


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);"

mjlorbet
04-29-2008, 02:14 AM
<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"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum