Caludaora cada situação um calculo diferente
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<htmL> <head> <title>Calculadora EuImport</title> <meta http-equiv="Content-Type" content="text/html. charset=UTF-8"> <script src="https://code.jquery.com/jquery-2.1.0.min.js"></script> <script> $(function() { $("#form-calcular").submit(function(e) { var cotacao_dolar = 2.37. e.preventDefault(). var peso = $("#peso").val(). peso = roundWeight(peso). var invoice = $("#total-invoice").val().replace(",", "."). var total = invoice / 4 + (peso * 2.2 / 100). $("#total-servico-us").val("U$ " + total.formatMoney(2, ',', '.')). var total_br = total * cotacao_dolar. total_br = total_br.formatMoney(2, ',', '.'). $("#total-servico-br").val("R$ " + total_br). }). }). function roundWeight(w) { if (w.length > 2) { var t = w.length - 2. var l = parseInt(w % 20). if (l > 0) { roundedResult = parseInt(w.substr(0, t)). roundedResult++. roundedResult = roundedResult * 100. return roundedResult. } else return w. } else { return 100. } } Number.prototype.formatMoney = function(c, d, t) { var n = this, c = isNaN(c = Math.abs(c))? 2: c, d = d == undefined? ",": d, t = t == undefined? ".": t, s = n < 0? "-": "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3? j % 3: 0. return s + (j? i.substr(0, j) + t: "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c? d + Math.abs(n - i).toFixed(c).slice(2): ""). }. </script> </head> <style type="text/css"> #wrapper { width:343px. margin:0 auto. font-family:Verdana, sans-serif. } label { cursor:pointer. } legend { color:#0481b1. font-size:16px. padding:0 10px. background:#fff. -moz-border-radius:4px. box-shadow: 0 1px 5px rgba(4, 129, 177, 0.5). padding:5px 10px. text-transform:uppercase. font-family:Helvetica, sans-serif. font-weight:bold. } fieldset { border-radius:4px. background: #fff. background: -moz-linear-gradient(#fff, #f9fdff). background: -o-linear-gradient(#fff, #f9fdff). background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#f9fdff)). / background: -webkit-linear-gradient(#fff, #f9fdff). padding:20px. border-color:rgba(4, 129, 177, 0.4). } input, textarea { color: #000000. background: #fff. border: 1px solid #CCCCCC. color: #aaa. font-size: 14px. line-height: 1.2em. margin-bottom:15px. -moz-border-radius:4px. -webkit-border-radius:4px. border-radius:4px. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) inset, 0 1px 0 rgba(255, 255, 255, 0.2). } input[type="text"], input[type="password"] { padding: 8px 6px. height: 22px. width:280px. } input[type="submit"] { background: #222. border: none. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3). text-transform:uppercase. color: #eee. cursor: pointer. font-size: 15px. margin: 5px 0. padding: 5px 22px. -moz-border-radius: 4px. border-radius: 4px. -webkit-border-radius:4px. -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3). -moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3). box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3). } textarea { padding:3px. width:96%. height:100px. } textarea:focus { background:#ebf8fd. text-indent: 0. z-index: 1. color: #373737. opacity:0.6. box-shadow:0 0 5px rgba(4, 129, 177, 0.5). border-color:#ccc. }.small { line-height:14px. font-size:12px. color:#999898. margin-bottom:3px. } </style> <body> <div id="wrapper"> <form id="form-calcular"> <fieldset> <legend>Cálculo Frete USA-BRA</legend> <div> <label for="peso">Peso Total em Gramas</label> <br /> <input type="text" name="peso" id="peso" /> </div> <div> <label for="total-invoice">Valor Total da Invoice U$</label> <br /> <input type="text" name="total-invoice" id="total-invoice" /> </div> <div> <label for="dolar-atual">Cota褯 do Dolar em 21/07/2014</label> <input type="text" id="dolar-atual" readonly value="R$ 2,37" /> </div> <div> <label for="total-servico-us">Total do Servi诠em U$</label> <input type="text" name="total-servico-us" id="total-servico-us" readonly/> </div> <div> <label for="total-servico-br">Total do Servi诠em R$</label> <input type="text" name="total-servico-br" id="total-servico-br" readonly/> </div> <input type="submit" name="submit" value="Calcular" /> </fieldset> </form> <p style="color:red. text-align:center. "><strong>Aten褯:</strong> O valor do frete nacional ainda n䯠estᡩnclu no servi诼/p> </div> </body> </html> Criei esta calculador que o usuário irá digitar um valor em g no primeiro e um valor em dólar no segundo. Ela pega o valor do primeiro campo e multiplica por 2.20, pega o valor do segundo campo e multiplica por 25%, em seguida soma os dois valores. Gostaria que quando o usuário digitasse um valor <=150,00 fosse pego o peso 2,30 e invoice 35%. Caso o valor fosse >=151,00 e <401, peso 2,30, invocie 30%. Será se alguém pode dar uma luz?Discussão (12)
Carregando comentários...