1

So i created a function to calculate something when the text box looses its focus, but, for some reason, it doesn't execute. What did i do wrong? When the page loads and document.ready executes, the breakpoint i added gets triggered, so its at least loading, but never executes again when i change the text box value

$(document).ready(function () {
    $('#txtVlrServicoLiberado').on('blur', function (e) {
        $('#txtVlrServicoGlosado').val() = $('#txtVlrServicoCobrado').val() - $('#txtVlrServicoLiberado').val();
    });
});

Im working with vb.net, this is the text box (Its inside a pop-up).

<asp:TextBox ID="txtVlrServicoLiberado" MaxLength="16" runat="server" alt="mascaraVlrServicoLiberado" ></asp:TextBox>
Vitor Ceolin
  • 111
  • 14
  • Maybe because that's not a valid HTML element? – weltschmerz Sep 02 '20 at 04:23
  • 3
    You might be getting `invalid left side assigment` .Check your browser console . Simple do `$('#txtVlrServicoGlosado').val(parseInt($('#txtVlrServicoCobrado').val()) - parseInt($('#txtVlrServicoLiberado').val())) ;` – Swati Sep 02 '20 at 04:24
  • No success, the code doesnt even stop at the breakpoint, so the function is not getting triggered – Vitor Ceolin Sep 02 '20 at 04:30
  • 1
    Any other errors in browser console ? Also ,check if the `ids` which you are using in your jquery are correct or not .Lastly are these inputs dynamically generated ? – Swati Sep 02 '20 at 04:35
  • 1
    I think it happens because the function document.ready happens but the pop up is not loaded (It only gets loaded after i click on a button. – Vitor Ceolin Sep 02 '20 at 04:40
  • 1
    *it gets loaded after I click a button* - then you need event delegation: `$(document).on("blur", "#txtVlrServicoLiberado", function...` – freedomn-m Sep 02 '20 at 09:14
  • Thanks for the help @freedomn-m how does this work exactly? – Vitor Ceolin Sep 02 '20 at 18:51

0 Answers0