title: How to use javascript for html form validation to valid number only?
body: <p>How to validate input form using Javascript to stretch user don't insert any value  into input form element.
  <strong>Object:</strong>
            1, I want user input any number value only if have some character or special character it will show errors
            2, and if user let input element value as empty it also alert to user</p>
  
  <p>below is my javascript code</p>
  
  <pre><code>&lt;script type="text/javascript"&gt; 
       $(document).ready(function(){
       $('.quantity, .unitprice').on('keyup', function(e){
       var errors = array[];
       var quantity = document.getElementsByClassName('.quantity').val(); 
       var unitprice = document.getElementsByClassName('.unitprice').val();
  
       if(quantity== ""){
           errors = "quantity is empty";
      }
         if(unitprice== ""){
               errors = "unitprice is empty";
          }eles{
           if(errors){
               forearch(errors as errors){
                   alert(errors);
                      }
              }else{
                   calculate();
               }
          }
      });
        function calculate(){
  
  
               var qty = parseFloat( $('.quantity').val() ), 
               unit = parseFloat( $('.unitprice').val() ); 
               if( isNaN(qty) || isNaN(unit) ) {
               $('.result').text('');
                return false;
                }
                  var total = qty * unit; 
                  $('.result').text(total);
  
           }
           });
  
          &lt;/script&gt;
  </code></pre>
  
  <p><strong>And here is Html form</strong> </p>
  
  <pre><code>&lt;td&gt;&lt;?php echo form_input('quantity','',' class="quantity form-control"')?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo form_input('unitprice','',' class="unitprice form-control"')?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;label class="result"&gt;&lt;/label&gt;$&lt;/td&gt;
  </code></pre>