• Resolved Viking

    (@hashtagfashion)


    Hi there,

    I can’t get the following formula to work.
    Am i doing something wrong?

    <script type=”text/javascript”>

    $(document).ready(function() {

    $(“#x”).focusout(function(){

    x = parseInt($(“#fieldname2”).val());

    if( x < 29 ) {
    a = 1;
    } else {
    a = Math.ceil(x / 30);
    }

    $(“.new_a”).html(a);

    });

    $(“#fieldname3”).focusout(function(){

    y = parseInt($(“#y”).val());

    if( y < 29 ) {
    b = 1;
    } else {
    b = Math.ceil(y / 30);
    }

    $(“.new_b”).html(b);
    });

    $(“#hesapla”).click(function(){
    //alert(‘kk’);
    var m = parseInt($(“#fieldname4”).val());
    var sonuc = Math.ceil((((((a+b)/(x/100))/(y/100))))*m);
    $(“.new_c”).html(sonuc);
    return false;
    });
    });

    </script>

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @hashtagfashion,

    Where are you entering the code? If you are entering the previous code as the equation associated to a calculated field its structure is wrong.

    You can enter the previous code as the content of a “HTML Content” field, and its structure should be modified as follows:

    
     <script type="text/javascript">
    	jQuery(document).ready(function ($) {
    
    		$("#x").focusout(function () {
    
    			x = parseInt($("[id*='fieldname2_']").val());
    
    			if (x < 29) {
    				a = 1;
    			} else {
    				a = Math.ceil(x / 30);
    			}
    
    			$(".new_a").html(a);
    
    		});
    
    		$("[id*='fieldname3_']").focusout(function () {
    
    			y = parseInt($("#y").val());
    
    			if (y < 29) {
    				b = 1;
    			} else {
    				b = Math.ceil(y / 30);
    			}
    
    			$(".new_b").html(b);
    		});
    
    		$("#hesapla").click(function () {
    			//alert('kk');
    			var m = parseInt($("[id*='fieldname4_']").val());
    			var sonuc = Math.ceil((((((a + b) / (x / 100)) / (y / 100)))) * m);
    			$(".new_c").html(sonuc);
    			return false;
    		});
    	});
    </script>
    

    I’m talking about the structure of the code, because I’m assuming that the fields’ ids and classes used in the code are correct.

    Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Formula not working’ is closed to new replies.