1
I have a Javascript function and it is returning me the following error:
Uncaught Typeerror: Cannot set Property 'value' of null
if (parseInt(data_inicio) < parseInt(dia_vencimento)) {
document.getElementById("<%= checkPorp.ClientID %>").checked = true;
document.getElementById("<%= checkPorp.ClientID %>").style.visibility = "visible";
document.getElementById("<%= lbValorPor.ClientID %>").style.visibility = "visible";
document.getElementById("<%= Label20.ClientID %>").style.visibility = "visible";
var valor = document.getElementById("<%= txtValorServico.ClientID %>").value;
valor = valor.replace(",", ".");
var dias = valor / 30;
var vencimento = dia_vencimento;
var porpocional = data_inicio - vencimento;
var qtd = porpocional * dias;
var resultado = valor - qtd;
var labe1 = document.getElementById('lbValorPor');
labe1.innerHTML = resultado.toFixed(2);
document.getElementById("<%= txtpropor.ClientID %>").value = resultado;
document.getElementById("<%= lbValorPor.ClientID %>").value = resultado;
}
It gives error in this line:
document.getElementById("<%= txtpropor.ClientID %>").value = resultado;
Only that in the Debugger of the code, the result has value, do not know why it returns me this error.
<asp:TextBox ID="txtpropor" runat="server" Enabled="True" ViewStateMode="Enabled" AutoPostBack="False" Visible="False"></asp:TextBox>
I tried every hint informed in the question: question link, but none solved my problem.
Because the
id
given by<%= txtpropor.ClientID %>
does not exist on the page– Isac
It exists, is on the same html page.
– Mariana
I used all the tips of this question, but none helped me.
– Mariana
Then work out a [mcve] posting the JS code generated by the application, showing what is the value of
txtpropor.ClientID
.– Woss
What is the HTML generated by txtpropor? and if Voce der
console.log(<%= txtpropor.ClientID %>)
Id is identical to the generated HTML?– BrTkCa
Yes, but it returns me this error, that because the result has value, I don’t know why it gives the error when passing the value to txtpropor.
– Mariana
@Lucascosta the funny, that if I comment this line of txtpropor, the code works as it should work, only q I need to pass the value to that txt,only that it informs this error.
– Mariana
He is giving this error because there is error somewhere. If you want we can continue on chat @marianac_costa
– BrTkCa
@Lucascosta we can, if you can help me
– Mariana
@Lucascosta I changed the line to this: $("#txtpropor"). val(result); and it worked, only now from the same error, in another, q pass the equal value was being passed before, this is a good practice ? I’m still new to javascript and jquery. Thank you.
– Mariana