Shortcut for jQuery update

I have 2 text fields and a shortcut on my page. 2 text fields will contain numerical values. Label text will be the product of two text field values. Is there a way to do this with jQuery so that the value can be updated when I edit text fields without the need for postback?

Also, text fields can contain comma-separated values: for example. 10000. Is there a way that I can extract from this number so that it can be used to calculate the label value.

Thanks in advance,

wants to give Petersburg

+3
source share
2 answers

, .

, , , .


function makeInt(text) {
  return parseInt(text.replace(',', ''));
}
$(function(){
  //hook all textboxes (could also filter by css class, if desired)
  //this function will be called whenever one of the textboxes changes
  //you could change this to listen for a button click, etc.
  $("input[type=text]").change(function(){
    var product = 1;
    //loop across all the textboxes, multiplying along the way
    $("input[type=text]").each(function() {
      product *= makeInt($(this).val());
    });
    $("#display-control-id").html(product);
  });
});
+1
$('#SecondTextbox').keyup(function() {
   var t1 = $('#FirstTexbox').val();
   var t2 = $(this).val();
   var result = t1+t2;
   $('#resultLabel').html(result);
});

, click . .

$('#checkButton').click(function() {
   var t1 = $('#FirstTexbox').val();
   var t2 = $('#SecondTextbox').val();
   var result = t1+t2;
   $('#resultLabel').html(result);
});

- :

<a id="checkButton" title="Check your result">Check</a>

css 'cursor: pointer;' .

0

Source: https://habr.com/ru/post/1747826/


All Articles