こんばんは。PHPページを作成して、ディレクトリを通過し、写真をテーブルに挿入します。これらの写真には、選択ドロップダウン ボックスと数量テキスト入力があります。各フォーム要素には、作成時のファイル名に基づいて名前が付けられます。数量値をjavascriptに渡すことができないようです。助けてください)。私のコードは以下に掲載されています。
for ($i=0; $i<count($files); $i++) {
echo $_POST[bandSelect];
if ($i%3 ==0 && $i!=0) {
echo '</tr><tr>';
}
$pricewallets = "$7.50"; $price3x5 = "$2.00";
$price4x6 = "$3.00"; $price5x7 = "$4.00";
$price8x10 = "$9.00"; $price11x14 = "$14.75";
$price12x18 = "$20.00"; $price16x20 = "$27.00";
$price18x24 = "$28.20";
$num = $files[$i];
list($width, $height, $type, $attr) = getimagesize($files[$i]);
echo '<td style="text-align:center;"><a href="'.$num.'" target="_blank">
<img src="'.$num.'" width ="'.($width/4).'" alt="random image"></a>';
$fileName = basename($num);
$qty = $num."qty";
echo "<br />".$fileName;
echo '<br /><select name="'.$num.'" id="'.$num.'">
<option value="'.$num.'Wallets">Wallets (8)</option>
<option value="'.$num.'3x5">3" x 5"</option>
<option value="'.$num.'4x6">4" x 6"</option>
<option value="'.$num.'5x7">5" x 7"</option>
<option value="'.$num.'11x14">11" x 14"</option>
<option value="'.$num.'12x18">12" x 18"</option>
<option value="'.$num.'16x20">16" x 20"</option>
<option value="'.$num.'18x24">18" x 24"</option>
</select>';
echo '<input type="text" name="'.$qty.'" id="'.$qty.'" size="1" value="0" />
<br />
<input type="button" name="addCart" value="Add to cart" onclick="addcart( \''.$num.'\',\''.$fileName.'\',\''.$qty.'\')" />
</td>';
}
ここに私のJavascriptがあります
function addcart(name, filename, qty)
{
var e = document.getElementById(name);
var strUser = e.options[e.selectedIndex].text;
var price;
var salePrice;
switch (strUser)
{
case "Wallets (8)":
salePrice = 7.5;
price = "$7.50";
break;
case "3\" x 5\"":
salePrice = 2;
price = "$2.00";
break;
case "4\" x 6\"":
salePrice = 3;
price = "$3.00";
break;
case "5\" x 7\"":
salePrice = 4;
price = "$4.00";
break;
case "8\" x 10\"":
salePrice = 9;
price = "$9.00";
break;
case "3\" x 5\"":
salePrice = 2;
price = "$2.00";
break;
case "11\" x 14\"":
salePrice = 14.75;
price = "$14.75";
break;
case "12\" x 18\"":
salePrice = 20;
price = "$20.00";
break;
case "16\" x 20\"":
salePrice = 27;
price = "$27.00";
break;
case "18\" x 24\"":
salePrice = 28.5;
price = "$28.50";
break;
}
var cartTotal=document.picSelect.cart.value;
if(strUser!=="Wallets (8)")
{
document.picSelect.cart.value = cartTotal + " " + filename + " " + strUser + "\t " + price + " x " + qty + "\n";
}
else
{
document.picSelect.cart.value = cartTotal + " " + filename + " " + strUser + " " + price + " x " + qty + "\n";
}
document.picSelect.Total.value = parseFloat(document.picSelect.Total.value) + salePrice * qty;
textTotal.innerHTML = "Your current total is:\n\t$" + parseFloat(document.picSelect.Total.value).toFixed(2);
}