HTML discount price calculation implementation principle and script code

HTML discount price calculation implementation principle and script code

Copy code
The code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<head>
<title>Price calculation after discount</title>
<!-- Set the price calculation event function, take different drop-down discount amounts, and send the calculation results to the text box-->
<script type="text/javascript">
function calculator(){
var prices = document.getElementById("price");
var discounts = document.getElementById("number");
var pay;
var select = document.getElementById("payfunction");
if((prices.value>=0&&!isNaN(prices.value))&&(discounts.value>=0&&!isNaN(discounts.value))&&prices.value!=""&&discounts.value!="")
{
pay=prices.value*discounts.value;
switch(parseInt(select.value)){
case 1:pay=pay*0.5; break;
case 2:pay=pay*0.8; break;
case 3:pay=pay*0.6; break;
}
document.getElementById("result").value=pay;
alert("Congratulations, the transaction is successful!");
}else
{
prices.focus();
prices.select();
alert("Please enter the correct price and quantity (cannot be empty)!");
}
}
</script>
</head>
<!-- Define the interface format, set the drop-down table, set the calculation price event-->
<body>
<center>
<form name="discount" action="result.jsp" method="post">
Bidding price: <input type="text" id="price" style="width: 150px"/>

Purchase quantity: <input type="text" id="number" style="width: 150px"/>

Payment method: <select id="payfunction" style="width: 150px">
<option value="1">Online banking payment - 50% discount</option>
<option value="2">Alipay payment - 20% off</option>
<option value="3" selected="true">Q coin payment - 40% off</option>
</select>

Estimated total price: <input type="text" id="result" style="width: 150px">

<input type="button" id="allresult" value="Calculate total price" onclick="calculator()" />
</form>
</center>
</body>
</html>

<<:  Detailed explanation of the JavaScript timer principle

>>:  How to set up vscode remote connection to server docker container

Recommend

Detailed explanation of dynamic Christmas tree through JavaScript

Table of contents 1. Animated Christmas Tree Made...

MySQL 5.7.12 installation and configuration tutorial under Mac OS 10.11

How to install and configure MySQL on Mac OS 10.1...

Use Python to connect to MySQL database using the pymysql module

Install pymysql pip install pymysql 2|0Using pymy...

How to quickly import data into MySQL

Preface: In daily study and work, we often encoun...

How to uninstall and reinstall Tomcat (with pictures and text)

Uninstall tomcat9 1. Since the installation of To...

Summary of Node.js service Docker container application practice

This article will not explain the use and install...

Centos6.5 glibc upgrade process introduction

Table of contents Scenario Requirements glibc ver...

Detailed explanation of flex and position compatibility mining notes

Today I had some free time to write a website for...

How to set static IP for Ubuntu 18.04 Server

1. Background Netplan is a new command-line netwo...

Example of using negative margin to achieve average layout in CSS

For evenly distributed layouts, we generally use ...

Markup Languages ​​- What to learn after learning HTML?

Click here to return to the 123WORDPRESS.COM HTML ...

MySQL Interview Questions: How to Set Up Hash Indexes

In addition to B-Tree indexes, MySQL also provide...

CentOS7 configuration Alibaba Cloud yum source method code

Open the centos yum folder Enter the command cd /...

A practical record of an accident caused by MySQL startup

Table of contents background How to determine whe...