Number Calculation : Number Data Type : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » Number Data Type »

 

Number Calculation





<html>
<head>
<title>Prices Demo</title>

<script language="javascript">

function calculation() {
  var number= document.prices.quantity.value;
  total = "" + Math.round((number*12.95)*100)/100;

  if (total.indexOf("."== -1
    total += ".00"
  else if (total.indexOf("."== total.length-2
    total += "0"

  document.prices.subtotal.value = total += "$";

}

</script>


</head>
<body>

<form name="prices">

<select name="quantity" onClick="calculation()">
  <option value="0">0</option>

  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>

  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
</select>

<br>


<input type="text" name="subtotal" value="0.00$">

</form>
</body>
</html>



           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» Number Data Type