I have this code:
It has a pop up that asks for a user name, then sets that name as a cookie. That part works.
I am trying to get it to pass that information to the main form,
"empinfo", then to an input box, "emplname".
but it doesn't seem to work.
I have this function:
which I was hoping would do the trick. but it isn't working.
can anyone help me ???
Thanks for your help....
james
PHP Code:
ffunction getName(nm) {
userName = nm;
msg.close();
now = new Date();
exp = new Date(Date.parse(now) + (86400000*365));
SetCookie("userName", userName, exp);
window.location.reload();
}
function askUserName() {
msg = window.open("","msg","top=500,left=500,height=100,width=300,dependent=yes,resizable=yes");
msg.focus();
msg.document.writeln("<body onLoad='document.f1.nm.focus()'>");
msg.document.writeln("<form name='f1' onSubmit='window.opener.getName(this.nm.value);return false'>");
msg.document.writeln("<table>");
msg.document.writeln("<tr>");
msg.document.writeln("<td>Please enter your name: </td>");
msg.document.writeln("<td><input name='nm' type='text'></td>");
msg.document.writeln("</tr>");
msg.document.writeln("<tr>");
msg.document.writeln("<td> </td>");
msg.document.writeln("<td><input type='submit' onsubmit='id()' value=' Submit '></td>");
msg.document.writeln("</tr>");
msg.document.writeln("</table>");
msg.document.writeln("</body>");
msg.document.close();
return false;
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
userName = GetCookie("userName");
if (!userName)
{askUserName();}
function checkUser() {
if (document.getElementById)
{if (userName) document.getElementById("empinfo").style.visibility = "visible";}
else {
if (document.layers)
{if (userName) document.empinfo.visibility = "visible";}
else
{if (userName) document.all.empinfo.style.visibility = "visible";}
}
}
function id(){
document.forms.empinfo.emplname.value = askUserName();
}
I am trying to get it to pass that information to the main form,
"empinfo", then to an input box, "emplname".
but it doesn't seem to work.
I have this function:
PHP Code:
function id(){
document.forms.empinfo.emplname.value = userName();
}
can anyone help me ???
Thanks for your help....
james
Comment