我如何乘以价格和金额?

时间:2015-06-22 09:50:45

标签: javascript php

如何将价格与金额相乘并显示结果。这是我想将所选价格乘以所选金额并显示结果的代码:

?>
<!DOCTYPE html>
<head>
<title>Order</title>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/custom.css" />
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<link rel="stylesheet" href="buttons.css">
</head>

<body>

$_SESSION['link'] = $_POST['link'];
echo '<img src="'.$_SESSION['link'] .'">'; 
?>

Order

<form action="" method="post" id="register-form" novalidate="novalidate">
ProductID: <input type="text" name="ProductID" id="ProductID">
Color: <input type="text" name="Color" id="Color">
Amount: <input type="number" name="Amount" id="Amount">
Price: echo ''.$_SESSION['price'].'';
?>

<input type="submit" name="submit" value="Submit" class="button">

</form> 

<script>

2 个答案:

答案 0 :(得分:1)

Demo on JS Fiddle.

HTML + PHP:

trap -l

JS:

<form action="" method="post" id="register-form" novalidate="novalidate">
    ProductID: <input type="text" name="ProductID" id="ProductID"/>
    Color: <input type="text" name="Color" id="Color"/>
    Amount: <input type="number" name="Amount" id="Amount"/>
    Price: <span id="price"><?php echo $_SESSION['price']; ?></span>
    <br/>
    Result: <span id="result"></span>

答案 1 :(得分:0)

使用

<input type="text" name="Price" id="Price" <?php echo ''.$_SESSION['price'].''; ?>>

并使用表单的属性 onSubmit 使用javascript或在给定页面上使用操作 <{1}}