skip to Main Content

I have an input text for checking if the corrected values are coming or not in alert. But when I open the form and change some value to check whether it takes the updated value in alert. It shows me the old value in alert.

Here is the code

$('#spnFiberLeadLITActual').keyup(function (evt) {
        var neValue = parseFloat($('#spnFiberLeadSpanLength').text());
        var completeValue = $('#spnFiberLeadLITAccepted').text();       

        alert(completeValue); // show the old value not the new value inserted in textbox

    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<td width="20%"><input type="text" class="text-center" id="spnFiberLeadLITActual" onkeypress="return isNumberKey(event, this)" /></td>

Here is the fiddle for the same

https://jsfiddle.net/49tvu0L8/

Please suggest what is wrong

2

Answers


  1. use $('#spnFiberLeadLITAccepted').val() instead of $('#spnFiberLeadLITAccepted').text()

    $('#spnFiberLeadLITActual').keyup(function (evt) {
        var neValue = parseFloat($('#spnFiberLeadSpanLength').text());
        var completeValue = $('#spnFiberLeadLITAccepted').val();       
    
        alert(completeValue); // show the old value not the new value inserted in textbox
    
    });
    
    Login or Signup to reply.
  2. Lots of mistakes:

    a) jQuery library missing

    b) To get the input box value use .val()

    c) function isNumberKey code is missing.

    d) onkeypress and keyup are both used on the same input. You can use one of them and apply all checks over there only

    Working snippet:

    $('#spnFiberLeadLITActual').keyup(function(evt) {
      var completeValue = $(this).val();
      alert(completeValue);
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <td width="20%">
      <input type="text" class="text-center" id="spnFiberLeadLITActual" />
    </td>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search