Jump to content
Fórum Script Brasil
  • 0

alguém poderia me ajudar com um código?


Walter Bega

Question

Oláá, estou estudando javascript e em um dos exercicios devo fazer um codigo para uma loja de donuts, onde quando for fornecido o numero de donut e donuts com cobertura deve-se automaticamente ser atribuido um valor aos campos taxa, subtotal e total. estou usando o comando onchange nos campos de donuts do formularios, porem, por algum motivo comando onchnge não esta realizando funçao nenhuma, vou mostrar como ta o código que é melhor:

<script type="text/javascript">

function updateOrder() {

const TAXRATE = 0.0925;

const DONUTPRICE = 0.50;

var numCakeDonuts = parseInt(document.getElementById("cake").value);

var numGlazedDonuts = parseInt(document.getElementById("glazedonut").value);

var subTotal = (numCakeDonuts + numGlazedDonuts) * DONUTPRICE;

var taxa = subTotal * TAXRATE;

var total = subTotal + taxa;

}

document.getElementById("tax").value = "$" + taxa.toFixed(2);

document.getElementById("subtotal").value = "$" + subTotal.toFixed(2);

document.getElementById("total").value = "$" + total.toFixed(2);

function placeOrder() {

//submit to server

form.submit();

}

</script>

</head>

<body>

...

<form method="post" id="form_entrega" action="Walter/fireworks/JavaScript/Use a Cabeça JS/donuts shop/donuts.php">

<div class="field">Name:<input type="text" id="name" name="name" align="right" /></div>

<div class="field"># of Cake Donuts:<input type="text" id="cake" name="cake" value="" onchange="updateOrder();"/></div>

<div class="field"># of Glazed Donuts:<input type="text" id="glazedonuts" name="glazedonuts" value="" onchange="updateOrder();" /></div>

<div class="field">Minuts til the pickup: <input type="text" id="pickup" /></div>

<div class="field">Subtotal:<input type="text" id="tax" value="$" /></div>

<div class="field">Tax:<input type="text" id="subtotal" value="$" /></div>

<div class="field">Total:<input type="text" id="total" value="$" /></div>

<div class="field"><input type="submit" value="Palce Order" onclick="placeOrder(this.form);" /></div>

</form>

obrigado a quem puder ajudar, não consigo entender porque o codigo não esta funcionando, não sei se falta algo na parte logica ou se foi algum erro grotesco de sintax, flww galra, vlw!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Tente assim:

<script type="text/javascript">
function updateOrder() {
const TAXRATE = 0.0925;
const DONUTPRICE = 0.50;
var numCakeDonuts = parseInt(document.getElementById("cake").value);
var numGlazedDonuts = parseInt(document.getElementById("glazedonut").value);

var subTotal = (numCakeDonuts + numGlazedDonuts) * DONUTPRICE;
var taxa = subTotal * TAXRATE;
var total = subTotal + taxa;

document.getElementById("tax").value = "$" + taxa.toFixed(2);
document.getElementById("subtotal").value = "$" + subTotal.toFixed(2);
document.getElementById("total").value = "$" + total.toFixed(2);
}

function placeOrder() {
//submit to server
form.submit();
}
</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...