เวลา back กลับมาแล้วข้อมูลหายหมดครับ ที่หน้าฟอร์มกรอกข้อมูลพอกดตกลงครับเพื่อเช็คเงื่อนไขที่เราเขียน แล้วกลับมาแก้ไขข้อมูลด้วย history.back(-1)
ยังแก้ไม่ได้อีกเหรอ ต้องการให้ข้อมูลที่กรอกไว้ไม่หาย หรือว่า session ไม่หายหล่ะ
Date :
22 ต.ค. 2550 16:51:28
By :
xboy
ทั้งสองอย่างครับ ต้องการใช้ session เพื่อเช็ค user ต้องการให้ข้อมูลที่เรากรอกมีอยู่เวลา back กลับมาแก้ไข
Date :
24 ต.ค. 2550 09:03:53
By :
bts
Code
<form name="frmMain" method="post" action="Sample2.php">
Name
<input type="text" name="textfield">
<br>
Surname
<input type="text" name="textfield2">
<br>
Email
<input type="text" name="textfield3">
<br>
<input name="btnSubmit" type="submit" id="btnSubmit" value="Submit" onClick="clsControlObject('frmMain','write')">
<input name="btnClear" type="button" id="btnClear" value="Clear" onClick="clsControlObject('frmMain','clear')">
</form>
<script language="JavaScript">
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 dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
</script>
<script language="JavaScript">
function clsControlObject(objForm,flgMode)
{
var form, ele_text,ele_hidden,ele_textarea,ele_hidden,ele_select,ele_hidden, i, elm;
form = document.getElementById
? document.getElementById(objForm)
: document.forms[objForm];
var valtext,valtextarea,valselect,valhidden
valtext = "";
valtextarea = "";
valselect = "";
valhidden = ""
if (document.getElementsByTagName)
{
'******************* Input type=text *******************'
ele_text = form.getElementsByTagName('input');
for( i=0, elm; elm=ele_text.item(i++); )
{
if (elm.getAttribute('type') == "text")
{
if(flgMode=="write")
{
if(elm.value != "")
{
valtext=valtext.concat(elm.name+'||'+elm.value)+'(|)'
}
}
else if(flgMode=="clear")
{
elm.value = ""
deleteCookie('cktext')
}
else if(flgMode=="read")
{
if(getCookie('cktext') != null)
{
splitString=getCookie('cktext').split("(|)")
for(j=0;j<=parseInt(splitString.length-1);j++)
{
splitStringValue=splitString[j].split("||")
if(elm.name == splitStringValue[0])
{
if(splitStringValue[1] != "")
{
elm.value = splitStringValue[1];
}
break;
}
}
}
}
}
}
if(flgMode=="write")
{
if(valtext != "")
{
setCookie('cktext',valtext)
}
}
'***************** end Input type=text *****************'
'******************* Input type=hidden *******************'
ele_hidden = form.getElementsByTagName('input');
for( i=0, elm; elm=ele_hidden.item(i++); )
{
if (elm.getAttribute('type') == "hidden")
{
if(flgMode=="write")
{
if(elm.value != "")
{
valhidden=valhidden.concat(elm.name+'||'+elm.value)+'(|)'
}
}
else if(flgMode=="clear")
{
elm.value = ""
deleteCookie('ckhidden')
}
else if(flgMode=="read")
{
if(getCookie('ckhidden') != null)
{
splitString=getCookie('ckhidden').split("(|)")
for(j=0;j<=parseInt(splitString.length-1);j++)
{
splitStringValue=splitString[j].split("||")
if(elm.name == splitStringValue[0])
{
if(splitStringValue[1] != "")
{
elm.value = splitStringValue[1];
}
break;
}
}
}
}
}
}
if(flgMode=="write")
{
if(valhidden != "")
{
setCookie('ckhidden',valhidden)
}
}
'***************** end Input type=hidden *****************'
'******************* Input type=textarea *******************'
ele_text = form.getElementsByTagName('textarea');
for( i=0, elm; elm=ele_text.item(i++); )
{
if (elm.getAttribute('type') == "textarea")
{
if(flgMode=="write")
{
if(elm.value != "")
{
valtextarea=valtextarea.concat(elm.name+'||'+elm.value)+'(|)'
}
}
else if(flgMode=="clear")
{
elm.value = ""
deleteCookie('cktextarea')
}
else if(flgMode=="read")
{
if(getCookie('cktextarea') != null)
{
splitString=getCookie('cktextarea').split("(|)")
for(j=0;j<=parseInt(splitString.length-1);j++)
{
splitStringValue=splitString[j].split("||")
if(elm.name == splitStringValue[0])
{
if(splitStringValue[1] != "")
{
elm.value = splitStringValue[1];
}
break;
}
}
}
}
}
}
if(flgMode=="write")
{
if(valtextarea != "")
{
setCookie('cktextarea',valtextarea)
}
}
'***************** end Input type=textarea *****************'
'******************* Input type=select *******************'
ele_text = form.getElementsByTagName('select');
for( i=0, elm; elm=ele_text.item(i++); )
{
if (elm.getAttribute('type') == "select-one")
{
if(flgMode=="write")
{
if(elm.value != "")
{
valselect=valselect.concat(elm.name+'||'+elm.value)+'(|)'
}
}
else if(flgMode=="clear")
{
elm.value = ""
deleteCookie('ckselect')
}
else if(flgMode=="read")
{
if(getCookie('ckselect') != null)
{
splitString=getCookie('ckselect').split("(|)")
for(j=0;j<=parseInt(splitString.length-1);j++)
{
splitStringValue=splitString[j].split("||")
if(elm.name == splitStringValue[0])
{
if(splitStringValue[1] != "")
{
for (x=0;x<elm.length;x++)
{
if (elm.options[x].value==splitStringValue[1])
{
elm.options[x].selected = true;
break;
}
}
}
break;
}
}
}
}
}
}
if(flgMode=="write")
{
if(valselect != "")
{
setCookie('ckselect',valselect)
}
}
'***************** end Input type=select *****************'
}
}
clsControlObject('frmMain','read');
</script>
Date :
2009-04-25 15:57:03
By :
webmaster
Load balance : Server 02