On change select allow only numbers and dot

Hy
I have problem when I want o change select options for payment
payment method, select the option of a cash, check, credit card, choosing to cash a check in the amount field should be entered integer, selecting cards that are allowed to enroll for the decimal number that is the point. I made a JavaScript but does not work too well not to accept changes to the selection. I have a button that adds add dynamically select print options and input for payment. each time a new payment method selected should each select valid for the closest row. When initially choose the card he does not respond only shows numbers without point and when added to the other and choose Payment by card on the field to accept the point number. Another problem is that when the select in same row choose the same option when changing option shall be made to change the code for example, you choose to pay cash and then on the same line card he chooses not to accept the item numbers and vice versa. It should react to any change in the same row
Here is the code:

 <!doctype html>
    
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title></title>
    <script src="jsquery.js"></script>
    </head>
    <body>
    <input tpe="button" value ="Add" onclick="addPayments">
    <div id="payment">
     <select  id="pay-with-1">
      <option value="1"></option>
      <option value="2">cash</option>
      <option value="3">check</option>
      <option value="4">ard</option>
    </select> 
    <input type="text" id="method-of-payments-1" name="method-of-payments-1">
    <br>
     <select id="pay-with-2">
      <option value="1"></option>
      <option value="2">cash</option>
      <option value="3">check</option>
      <option value="4">ard</option>
    </select> 
    <input type="text" id="method-of-payments-2" name="method-of-payments-2">
    <br>
     <select  id="pay-with-3">
      <option value="1"></option>
      <option value="2">cash</option>
      <option value="3">check</option>
      <option value="4">ard</option>
    </select> 
    <input type="text" id="method-of-payments-3" name="method-of-payments-3">
    </div>
    <script>
    $(":input").keypress(function(event) {
              if ( (event.which < 48 || event.which > 57)) 
            {
                  event.preventDefault();
             }
    
    $('#payment').on('change', '*[id*=pay-with-]', function(){
        //get value of selected values    
         var option = $("option:selected", this).val();
        var pay = $(this).closest("tr").find('*[id*=method-of-payments-]');
     
        if(option == 3)    
        {
            pay .keypress(function(event) {
              if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) 
            {
                  event.preventDefault();
             }
        });
        
        }
        else
        {
            pay .keypress(function(event) {
              if ( (event.which < 48 || event.which > 57)) 
            {
                  event.preventDefault();
             }
        }
    
    });
    </script>
    </body>
    </html>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.