<script type="text/javascript">
function updatePrice() {
var price = document.getElementById("product").value;
var size_price = document.getElementById("size").value;
var a=parseInt(price);//parsed type price
var b=parseInt(size_price);//parsed size price
if(size_price != "null")//if the value selected is not null then add the prize
{
var fin_price = a+b; //add the prices
}
else //if the value selected is null then fin_prize=price
{
var fin_price = price;
}
document.getElementById("price").innerHTML="<p> <mark> PRICE: € " + fin_price + " </mark></p>";
}
</script>
<form method="post" action="http://atlantis.cit.ie/displayvalues.php" form onsubmit='return phoneValidation(),validateCard(this),euroValidation()'>
<h2>Order Form</h2>
<label >Shirt Type</label>
<body onload="updatePrice()">
<select id="product" onchange="updatePrice()">
<option id="basic" value="20.00"> Basic Shirt (€20.00)</option>
<option id="poly" value="25.00">Poly-Cotton Blend (€25.00)</option>
<option id="gildan" value="28.00">Gildan Cotton (€28.00)</option>
<option id="organic" value="30.00">Organic Cotton (€30.00)</option>
</select>
<br>
<label >Shirt Size</label>
<select id="size" onchange="updatePrice()">
<option id="None" value="null">Choose Size</option>
<option id="Small" value="0.00" value= "Small">Small</option>
<option id="Medium" value="0.00" value= "Medium">Medium</option>
<option id ="Large" value="0.00" >Large</option>
<option id ="XL" value="0.00">XL</option>
<option id ="XXL"value= "2.00">XXL (+€2)</option>
<option id ="XXXL" value="3.00">XXXL (+€3)</option>
</select>
<br>
<label >Character</label>
<select id="character" name='character'>
<option value="None">Choose Character</option>
<option value="Sonic">Sonic</option>
<option value="Drake">Drake</option>
<option value="Joel">Joel</option>
<option value="GTA">Grand Theft Auto</option>
<option value="Mario">Mario</option>
<option value="Ezio">Ezio</option>
</select>
<br/>
<label >Shirt Colour</label>
<select id="colour" required name='colour'>
<option value="None">Choose Colour</option>
<option value="Red">Red</option>
<option value="Grey">Grey</option>
<option value="Blue">Blue</option>
</select>
<div id="price"><p><mark>PRICE: €XX.XX</mark></p></div>
<br/>
<label>Name:</label>
<input id="name" name="name" required placeholder="Name" type="text" autofocus > <br>
Address:
<br>
<TEXTAREA NAME="address"
required ROWS="3" COLS="25">
</TEXTAREA> <br>
<label>Email:</label>
<input id="email" name="email" required placeholder="Email" type="text"> <br>
<label>Sex:</label>
<input id="male" name="sex" required type="radio" value="Male">
<label>Male</label>
<input id="female" name="sex" type="radio" value="Female">
<label>Female</label> <br>
<label>Phone No:</label>
<input id="phone" name="phone" placeholder="Mobile No." type="text"> <br>
<label>EBNS:</label>
<input id="EBNS" name="EBNS" placeholder="EBNS No." type="text"> <br>
<label>Card No:</label>
<input id="cardno" name="cardno" placeholder="Card No." type="text"> <br>
<input type="submit" value="Buy Now">
</form>
我有这个功能决定了产品的价格,但我还需要根据个人电子邮件地址提供折扣,如果它包含某些字符,但我无法理解它。我尝试过像下面的代码那样的东西,但它没有用,有人能解释一下吗?
if (validEmail.indexOf("@mycit.ie") > -1) {
{discount = .10}
totalCost=totalCost*discount;
document.getElementById("price").innerHTML="<p> <mark> PRICE: € " + totalCost + " </mark></p>";
} else {
totalCost=totalCost
}
}
答案 0 :(得分:0)
获取totalCost,而不仅仅是您需要使用的折扣金额
totalCost=totalCost - (totalCost*discount)
还要确保您的块在将fin_price设置为相同元素(价格)之后运行