...

View Full Version : Jquery If Statement Assistance



Popsicletoes
01-25-2012, 04:46 PM
Hello,
I have a form that calculates a dollar amount based on the percentage entered by the user. Now the client wants the form to also calculate the percentage if the user enters a dollar amount. I am new to this so I am having trouble figuring out how to format the if statement. Here is the code that performs the calculations:


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".TextBox").hover(function(){
$(this).toggleClass('TextBoxSelected');
},function(){
$(this).toggleClass('TextBoxSelected');
}).change(function(){
calculate();
});
});
function getFldValue(fldValue) {
return isNaN(fldValue) ? 0 : parseFloat(fldValue);
}
function calculate() {
var property_SPrice = getFldValue($('#property_SPrice').val());
var price = getFldValue($('#price').val());

var REO_sale_percentage = getFldValue($('#REO_sale_percentage').val());
var REO_sale_dollars = getFldValue($('#REO_sale_dollars').val());
var REO_sale_bonus_dollars = getFldValue($('#REO_sale_bonus_dollars').val());
var REO_sale_fixed_dollars = getFldValue($('#REO_sale_fixed_dollars').val());
var REO_sale_total_dollars = getFldValue($('#REO_sale_total_dollars').val());


var REO_list_percentage = getFldValue($('#REO_list_percentage').val());
var REO_list_dollars = getFldValue($('#REO_list_dollars').val());
var REO_list_bonus_dollars = getFldValue($('#REO_list_bonus_dollars').val());
var REO_list_fixed_dollars = getFldValue($('#REO_list_fixed_dollars').val());
var REO_list_total_dollars = getFldValue($('#REO_list_total_dollars').val());

var gr_comm_percentage = getFldValue($('#gr_comm_percentage').val());
var gr_comm_dollars = getFldValue($('#gr_comm_dollars').val());
var gr_bonus_dollars = getFldValue($('#gr_bonus_dollars').val());
var gr_fixed_dollars = getFldValue($('#gr_fixed_dollars').val());
var gr_total_dollars = getFldValue($('#gr_total_dollars').val());

$('#price').val(property_SPrice);
$('#gr_comm_percentage').val(REO_list_percentage + REO_sale_percentage);

$('#gr_comm_dollars').val(getFldValue(REO_list_dollars + REO_sale_dollars));
$('#REO_list_dollars').val(getFldValue(REO_list_percentage/100*price));
$('#REO_sale_dollars').val(getFldValue(REO_sale_percentage/100*price));
$('#gr_fixed_dollars').val(getFldValue(REO_list_fixed_dollars + REO_sale_fixed_dollars));
$('#gr_bonus_dollars').val(getFldValue(REO_list_bonus_dollars + REO_sale_bonus_dollars));
$('#gr_total_dollars').val(getFldValue(REO_sale_total_dollars + REO_list_total_dollars));
$('#REO_sale_total_dollars').val(getFldValue(REO_sale_dollars + REO_sale_fixed_dollars + REO_sale_bonus_dollars));
$('#REO_list_total_dollars').val(getFldValue(REO_list_dollars + REO_list_fixed_dollars + REO_list_bonus_dollars));

}
</script>


I now need to add:


$('#REO_list_percentage').val(getFldValue(REO_list_dollars/price*100));
$('#REO_sale_percentage').val(getFldValue(REO_sale_dollars/price*100));

So that if the user enters a dollar amount, the form can calculate the percentage along with all of the other calculations above. How would I write that? Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum