私は、Cookie を使用するプログラムに取り組んでいます。ショッピングカートアプリです。私が尋ねたいのは、ユーザーが入力した正確な値を取得して、Cookie に保存する方法はありますか?
私のページの設定方法は、価格が既に設定されているテーブルに 2 つの項目があり、ユーザーは数量のみを入力することです。ユーザーは数量を入力し、[カートに追加] をクリックしてから、リンクをクリックしてカートを表示します。このリンクにより、ユーザーは別のページに移動し、そのアイテムの数量、価格、および合計価格が表に表示されます。
カートの表示ページに、ユーザーが入力した数量が表示されるようになりました。しかし、次の問題は、表示される各アイテムの合計を取得することです。retr() 関数の最後のコード行を試してみましたが、成功しませんでした。何か案は?これは私のカートを見るリンクページです
<html>
<head>
<title> Cart </title>
<h1> My cart </h1>
<script type = "text/javascript">
function retr()
{
var cke = document.cookie;
if (cke.length>0) {
start = cke.indexOf("Circle=");
if (start!= -1) {
start = start + 7
end = cke.indexOf("$", start);
if (end == -1) end = cke.length;
qu1 = cke.substring(start, end);
document.getElementById("q1").value = qu1;
}
}
if (cke.length>0) {
start = cke.indexOf("$");
if (start!= -1) {
start = start + 1
end = cke.indexOf("e", start);
if (end == -1) end = cke.length;
pr1 = cke.substring(start, end);
document.getElementById("p1").value = pr1;
}
}
if (cke.length>0) {
start = cke.indexOf("Stickman=");
if (start!= -1) {
start = start + 9
end = cke.indexOf("$", start);
if (end == -1) end = cke.length;
qu2 = cke.substring(start, end);
document.getElementById("q2").value = qu2;
}
}
if (cke.length>0) {
start = cke.indexOf("$");
if (start!= -1) {
start = start + 55
end = cke.indexOf("e", start);
if (end == -1) end = cke.length;
pr2 = cke.substring(start, end);
document.getElementById("p2").value = pr2;
}
}
document.getElementById("t1").value = qu1 * pr1;
document.getElementById("tot").value = document.getElementById("t1") + document.getElementById("t2");
}
</script>
</head>
<body onload = "retr()">
<table border = "1">
<td>Circle </td>
<td><input type = "text" size = "8" id = "q1" readonly = "readonly" /></td>
<td> <input type = "text" size = "8" id = "p1" readonly = "readonly" /> </td>
<td> <input type = "text" size = "8" id = "t1"> </td>
<tr> </tr>
<td> Stickman </td>
<td> <input type = "text" size = "8" id = "q2" readonly = "readonly" /></td>
<td> <input type = "text" size = "8" id = "p2" readonly = "readonly" /> </td>
<td> <input type = "text" size = "8" id = "t2"> </td>
<tr> </tr>
<td colspan = "3"> TOTAL: </td>
<td> <input type = "text" size = "8" id = "tot"> </td>
</table>
<br /> <br />
<input type ="text" id = "ret" readonly = "readonly" />
<br / > <br />
<input type = "button" value = "Checkout">
<br /> <br />
<a href = "store.html" > Continue Shopping </a>
</body>
</html>