Calling function that is inside another

Asked

Viewed 40 times

0

Html:

<html>
<head>
    <title>
        Caixa Eletrônico
    </title>
    <meta charset="utf-8">
    <link rel="icon" href="http://icon-icons.com/icons2/516/PNG/512/cash_icon-icons.com_51090.png" type="image/x-icon" />
    <link href="estilo_caixa.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
    <script src="Java_caixa_eletronico.js"></script>
</head>

<body>
    <div id="cabecalho">
        <img src="http://ganhardinheiropassoapasso.com.br/wp-content/uploads/2015/07/finance-634901_640-e1437792408793.png?x21126"> 
    </div>
    <div id="cabecalho2">
        <font color="white" size="36">Banco Nacional</font>
    </div>
    <div id="cabecalho">
        <img src="http://ganhardinheiropassoapasso.com.br/wp-content/uploads/2015/07/finance-634901_640-e1437792408793.png?x21126"> 
    </div>
    <div id="corpo">
        <h1>Retirada de dinheiro</h1>
        <form>
            Valor do saque R$: <input type="text" placeholder="Digite aqui" id="valor">
            <br/>
            <br/>
            <input type="submit" value="Consultar" name="Consulta" onclick="Calcula()">
            <br/>
            <br/>
            <hr color="white" size="3">
            <h4>Depois de clicar no botão "Consultar" siga o link abaixo:</h4>
            <br/>
            <br/>
            <a href="notas.html">Verificar o saque</a>
        </form>
    </div>  
</body>
</html>             

Function in Javascript:

function Calcula() {

var valor_digitado = parseInt(document.getElementById("valor").value);
var q_100 = 0;
var q_50 = 0;
var q_20 = 0;
var q_10 = 0;
var q_5 = 0;
var q_2 = 0;
var q_1 = 0;

while (valor_digitado != 0){ 

    if ((valor_digitado%100) == 0) {

        q_100 = q_100 + 1;
        valor_digitado = (valor_digitado - 100);
    }

    else if ((valor_digitado%50) == 0) {

        q_50 = q_50 + 1;
        valor_digitado = (valor_digitado - 50);
    }

    else if ((valor_digitado%20) == 0) {

        q_20 = q_20 + 1;
        valor_digitado = (valor_digitado - 20);
    }

    else if ((valor_digitado%10) == 0) {

        q_10 = q_10 + 1;
        valor_digitado = (valor_digitado - 10);
    }

    else if ((valor_digitado%5) == 0) {

        q_5 = q_5 + 1;
        valor_digitado = (valor_digitado - 5);
    }

    else if ((valor_digitado%2) == 0) {

        q_2 = q_2 + 1;
        valor_digitado = (valor_digitado - 2);
    }

    else {

        q_1 = q_1 + 1;
        valor_digitado = (valor_digitado - 1);
    }
}

function escreve100(){

    alert("Quantidade de notas de 100: "+q_100);
}

function escreve50(){

    alert("Quantidade de notas de 50: "+q_50);
}

function escreve20(){

    alert("Quantidade de notas de 20: "+q_20);
}

function escreve10(){

    alert("Quantidade de notas de 10: "+q_10);
}

function escreve5(){

    alert("Quantidade de notas de 5: "+q_5);
}

function escreve2(){

    alert("Quantidade de notas de 2: "+q_2);
}

function escreve1(){

    alert("Quantidade de moedas de 1: "+q_1);
}
}

I want to call each of these functions "write" in buttons in html, but I’m not getting it. The buttons are all like this and should call an Alert containing the amount of notes, which is not happening, with their respective functions (this is the button that should show the amount of hundred notes):

<input type="submit" value="Mostrar quant. notas de 100" name="quan100" 
onclick="escreve100()">
  • 1

    "Not getting" why? By the way, this repetition of code is very unnecessary. You should improve this.

  • When I press the button, Alert with the amount of notes is not displayed

  • 'Cause he tries to do submit, exchange these input with normal buttons.

  • Subtitui type="Submit" by type="button", but the message is not yet displayed

  • where is the element with id="valor"?

  • It’s another html file, I’ll put it up

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.