Validation with Java Script

1

Expensive;

I created a function in Java Script, where this function is to take the current date and by this date, as the user selects the flag of his card, calculate if the invoice will be inserted in the table of the current month or in the next month, according to the due date and closing date of it.

Follow function:

 <script>
function finance() {

var dtcompra = document.getElementById("payment").value;
var datacompra = new Date(dtcompra);
var diacompra = datacompra.getDate();
var mespgto = document.getElementById("mespgto");
var itemSelecionado = mespgto.options[mespgto.selectedIndex].value;

var diamanualnubank = 25; // Vencimento Nubank
var diamanualamex = 15; // Vencimento Amex
var diamanualsantanderplatinum = 17; // Vencimento Santander Plantinum

// Função para retornar a data Atual
var data = new Date();
var dia = data.getDate();
   if (dia.toString().length == 1)
      dia = "0"+dia;
var mes = data.getMonth()+1
    if (mes.toString().length == 1)
    mes = "0"+mes;
var ano = data.getFullYear();  
//var data = ano+"/"+mes+"/"+dia;


if (itemSelecionado == 'nubank' && diacompra < 18) {


document.getElementById('maturity').value = ano+"/"+(data.getMonth()+1)+"/"+diamanualnubank;

    } else {
    document.getElementById('maturity').value = ano+"/"+(data.getMonth()+2)+"/"+diamanualnubank;

  return false;
}

if (itemSelecionado == 'amex' && diacompra > 10 &&  diacompra < 30) 

document.getElementById('maturity').value = ano+"/"+(data.getMonth()+1)+"/"+diamanualamex;

    else  {
    document.getElementById('maturity').value = ano+"/"+(data.getMonth()+2)+"/"+diamanualamex;

        return false;
}


if (itemSelecionado == 'santanderplatinum' && diacompra < 10) 

document.getElementById('maturity').value = ano+"/"+(data.getMonth()+1)+"/"+diamanualsantanderplatinum;

    else  {
    document.getElementById('maturity').value = ano+"/"+(data.getMonth()+2)+"/"+diamanualsantanderplatinum;

        return false;
}


}
</script>

If the current date is 10/09/2016 for ex and you select amex, you should fill in the due date for 2016/09/15, if the current date is greater than 10, the completion of this input should be 2016 / 10/15. Simulating here, the completion is with the expiration date of the 2016/10/25 Nubank. I'm not finding where I'm going wrong in logic. I'm not very good with Java Script and so I turn to you.

I count on your help. Thank you.

    
asked by anonymous 27.09.2016 / 17:23

0 answers