دنبال کننده ها

۱۳۹۶ مهر ۸, شنبه

How to add data validation in function in javascript

[ad_1]

I'm writing a javascript like this:



var $ = function (id) 
return document.getElementById(id);

var calculate_click = function ()
var subtotal = parseFloat( $("subtotal").value );
var taxRate = parseFloat( $("tax_rate").value );

var salesTax = subtotal * taxRate/100;
var total= subtotal + salesTax;

document.getElementById("sales_tax").value = salesTax;
document.getElementById("total").value = total;


var clear_click = function ()



window.onload = function ()
document.getElementById("calculate").onclick = calculate_click



  1. Could you help me add a data validation to this application? The subtotal entry should be a valid, positive number that’s less than 30,000. The tax rate should be a valid, positive number that is less than 15. The following error messages should be displayed in the alert window when errors occur "Must be a positive number less than $30,000, Must be a positive number less than 15"

  2. Could you help me add a code that enables the clear button work?

Thanks in advance



[ad_2]

لینک منبع