Caculation field - Post ID 227695

User 187934 Photo


Senior Advisor
20,265 posts

Try this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#item1_number_1').keyup(function(){
var valone = $('#item1_number_1').val();
var valtwo = 5;
var valthree = 1.014;
var total = valone + valtwo;
var value = parseFloat(total).toFixed(2);
$('#item2_number_1').val(value);
});
});</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2230719 Photo


Registered User
16 posts

Thanks a lot.
User 2657606 Photo


Registered User
11 posts

Hi, I have an issue with a calculated field also. When the two fields are added together and put in the total, they aren't added together, more like appended together. How do you get the two fields actually added together? I've tried different things, but nothing worked. Thanks for the help. Kevin

http://dtproperties.com/deposit.htm

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
//////Take deposit amount and multiply by 4% and have it show in the total.//////

type="text/javascript">$(document).ready(function(){
$('#item2_number_1').keyup(function(){
var valone = $('#item2_number_1').val();
var valtwo = .04;
var subtotal = ((valone * valtwo));
var total = ((valone + subtotal));
var value1 = parseFloat(subtotal).toFixed(2);
$('#item3_number_1').val(value1);
var value2 = parseFloat(total).toFixed(2);
$('#item5_number_1').val(value2);
});
});</script>
User 187934 Photo


Senior Advisor
20,265 posts

If I'm understanding you correctly.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
//////Take deposit amount and multiply by 4% and have it show in the total.//////

type="text/javascript">$(document).ready(function(){
$('#item2_number_1').keyup(function(){
var valone = $('#item2_number_1').val();
var valtwo = 1.04;
var subtotal = (valone * valtwo);
var value1 = parseFloat(subtotal).toFixed(2);
$('#item3_number_1').val(value1);
});
});</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2657606 Photo


Registered User
11 posts

That was close, but it showed me a different way. So I used 2 values *.04 and *1.04 and put them in the form fields. Works just like I wanted it to. Thanks Eric.

http://dtproperties.com/deposit.htm

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript">$(document).ready(function(){
$('#item2_number_1').keyup(function(){
var valone = $('#item2_number_1').val();
var valtwo = .04;
var valthree =1.04;
var subtotal = ((valone * valtwo));
var total = ((valone * valthree));
var value = parseFloat(total).toFixed(2);
$('#item3_number_1').val(subtotal.toFixed(2));
$('#item5_number_1').val(value);
});
});</script>
User 187934 Photo


Senior Advisor
20,265 posts

Cool, It just comes down to what you need and if I understand it.:lol:
Glad you got it you needed it.:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2657606 Photo


Registered User
11 posts

I'm at a loss on this one. Same form as above but with a state drop down added. If a user selects Non U.S. from the drop down, then the Convenience fee goes from 4% to 5%, automatically calculated as before. Any help would be appreciated.
The field id is item7_select_1
Non U.S id is item7_1_option
User 187934 Photo


Senior Advisor
20,265 posts

Try this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function calculate(){
var valsel = $('[name="select7"] option:selected').val();

if(valsel != "Non U.S."){
var valone = 1.04;
var fee = .04;
}
else {var valone = 1.05;
var fee = .05;
}
$('#item3_number_1').val(fee);

var valtwo = $('#item2_number_1').val();

if(valtwo!=""){

var total = valtwo * valone;
var value = parseFloat(total).toFixed(2);

$('#item5_number_1').val(value);

}
}
</script>


Then in the form html you need to hook the function to the inputs that change.
<select name="select7" id="item7_select_1" onChange="calculate()" required data-hint="">
<input name="number2" id="item2_number_1" autofocus required type="number"
min="0" max="999999999" step="1" autocomplete="off" data-hint="" onkeyup="calculate()" />

Then in the form html you need to add readonly to the inputs attributes that are being calculated so users can't alter them.
<input name="number3" id="item3_number_1" type="number" min="0" max="999999999"
step="1" autocomplete="on" data-hint="" readonly />
<input name="number5" id="item5_number_1" type="number" min="0" max="999999999"
step="1" autocomplete="on" data-hint="" readonly />
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2657606 Photo


Registered User
11 posts

Thank you Eric for all your help. This is so close. How can I get field "item3_number_1" to show the total of "item2_number_1" * the selected var fee? I want the tenant to see how much the fee $ amount is so they can back out if they don't want to pay the fee.

http://dtproperties.com/deposit.htm

I'm trying to take all the rental forms we have now and make them more condensed and interactive by using conditionals. This is proving to be more difficult than I thought. I had never heard of jquery before now. So much to learn... Thanks, Kevin
User 187934 Photo


Senior Advisor
20,265 posts

It looks like it is doing that or am I missing something.
If the fee = .05
deposit = 2
fee x deposit 2 x .05=.1
total = 2.1
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.