|
|
|
อยากได้ JavaScript ที่เวลา Refresh ข้อมูลใน textbox ไม่หาย |
|
|
|
|
|
|
|
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 17:11:55 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไม ลองเอาไปใช้แล้ว พอ refresh ค่าใน textarea กับ select ยังหายอยู่คะ
แต่ใน text ใช้ได้นะคะ
|
ประวัติการแก้ไข 2010-10-11 13:33:11
|
|
|
|
Date :
2010-10-11 12:07:18 |
By :
sizzle |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
บทความนี้ครับ
jQuery วิธี Save Stage Form เมื่อกด Refresh หรือ Back แล้วข้อมูลบน Form ไม่หาย
|
|
|
|
|
Date :
2017-01-27 17:05:15 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|