C
C
crwbr2018-02-22 00:35:01
Web development
crwbr, 2018-02-22 00:35:01

Calculator JS displaying the result when not all fields are filled?

The problem is, there is a calculator that calculates if all fields are filled, but you need to do this if any field is not filled, then the value 0 will be assigned, and the result will come out without taking into account the filled imput
CODE:

spoiler
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>




 $(document).ready(function(){

     
      
      $('.hidden_field').parent().hide();
      
      $('#get_result').click(function(){
        
        var sure_field_count = 0;

        $('.sure_field').each(function(){   
          if( $(this).val() == '' ) sure_field_count++;     
        });

        if( sure_field_count == 0 ){
          
          eval(" result_proc =((parseFloat($('#id_3 input').val())*310)+(parseFloat($('#id_2 input').val())*280)+(parseFloat($('#id_1 input').val())*510)+(parseFloat($('#id_7 input').val())*500)+(parseFloat($('#id_6 input').val())*240)+(parseFloat($('#id_4 input').val())*220))*parseFloat($('#id_5 option:selected').val())");
         

          if( isNaN(result_proc) ) $('#view_result').html('Поля заполнены неверно!');
          else $('#view_result').html(result_proc.toFixed(1));  
        }       
        else $('#view_result').html('Не заполнены обязательные поля!');
      });
;
    });




</script>



<div id='placeForText'></div>

<div id='result_calc_page' style='width:378px;min-height:476px;background:#F7F7F7;border:7px dashed #DA5460;padding:10px;'>
<p class="sortable" id="id_3" style="">Площадь кухни (кв.м)<br><input placeholder="" type="input" value="" style="width: 100%;"></p><p class="sortable" id="id_2">Площадь жилых комнат (кв.м)<br><input placeholder="" type="input" value="" style="width: 100%;"></p><p class="sortable" id="id_1" style="">Площадь ванной комнаты (кв.м)<br><input placeholder="" type="input" value="" style="width: 100%;"></p><p class="sortable" id="id_7" style="">Площадь санузла (кв.м)<br><input placeholder="" type="input" value="" style="width: 100%;"></p><p class="sortable" id="id_6" style="">Площадь нежилых помещений (кв.м)<br><input placeholder="" type="input" value="" style="width: 100%;"></p><p class="sortable" id="id_4">Площадь лоджии(балкона) (кв.м)<br><input placeholder="" type="input" value="" style="width: 100%;"></p><p class="sortable" id="id_5" style=""><select style="width: 100%;"><option value="1">Косметический ремонт</option><option value="1.65">Ремонт "Комфорт"</option><option value="2.9">Ремонт "Люкс"</option></select><input type="select" style="display:none;"></p>
</div>
<br><p id='view_result'></p>
<button id='get_result' class="btn-slideshow calcum-knopka">Рассчитать</button>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question