Notice
Recent Posts
Recent Comments
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

Without haste, but without rest

[js] cookie id 저장 본문

삽질의 리포팅

[js] cookie id 저장

느린구름 2012. 2. 22. 11:18

function setCookie (name, value, expires) {

    document.cookie = name + "=" + escape (value) + "; path=/; expires=" + expires.toGMTString();

}


function getCookie(cookieName) {   

    var result = "";

    var allCookies = document.cookie.split("; ");

    var cookieArray = null;

    for(i=0;i<allCookies.length;i++) {

        cookieArray = allCookies[i].split("=");

        if(cookieName == cookieArray[0]) {

            result = cookieArray[1];

            break;

        }

    }

    return result;

}


function saveid(form) {

    var expdate = new Date();

    if (form.checkId.checked) {

        expdate.setTime(expdate.getTime() + 1000 * 3600 * 24 * 30); // 30일

        setCookie("saveid", form.USERID.value, expdate);

    } else {

        expdate.setTime(expdate.getTime() - 1); 

    }

    

}


function setUserId() {

var userId = getCookie("saveid");

if(userId != "") {

document.getElementById("USERID").value = userId;

document.getElementById("checkId").checked = true;

document.getElementById("PASSWD").focus();

} else {

document.getElementById("USERID").focus();

}

}


window.onload = function() {

setUserId();

};



<form name="loginForm"> 

<input name="USERID" />
<input password="PASSWD" />
<input type="checkbox" id = "chekId" name="checkId" /> 
 


</form>