この機能を備えたフォームに入力して、1つのページにCookieを保存しています:
<script type="text/javascript">
function WriteCookie()
{
emailValue = escape(document.form.01_email.value) + ";";
userIDValue = escape(document.form.01_userID.value) + ";";
document.cookie="email=" + emailValue;
document.cookie="userID=" + userIDValue;
}
</script>
<form name="form">
<input type="email" class="form-textbox validate[required, Email]" id="input_10" name="01_email" size="26" value="email@email.com" />
<input type="hidden" id="simple_spc" name="01_userId" value="1234" />
</form>
ユーザーがフォームを送信すると別のページにリダイレクトされ、このコードで Cookie を取得しますが、Cookie で電子メールとユーザー ID を見つけて、この新しいページの入力の値に挿入する必要があります。
<script type="text/javascript">
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++){
name = cookiearray[i].split('=')[1];
value = cookiearray[i].split('=')[2];
alert("Email is : " + name + " and UserID is : " + value);
}
}
</script>
<form name="form">
<input type="email" class="form-textbox" id="input_10" name="02_email" size="26" value="" />
<input type="hidden" id="simple_spc" name="02_userId" value="" />
</form>
ユーザーが複数の Cookie を持っている可能性が高いことはわかっているため、問題が発生している電子メールとユーザー ID のみを見つけます。