Help with some code please for price...

User 2377814 Photo


Registered User
45 posts

Could I please ask for help with how to create a code which will calculate a price and then check out.
The price will be £14 per 1000 or part thereof with no limit on the amount they can order

The customer will enter a quantity.
up to 1,000 price £14, up to 2,000 £28 etc
I can't do it with a dropdown menu as they need to enter a specific quantity e.g. 8,522

Can anyone please help with how i create the parameters for the code to round the figure up to the nearest 1,000 and then multiply by 14

Many thanks
User 187934 Photo


Senior Advisor
20,190 posts

Hi MG,
Can you share a link to your form?
This way I know exactly which inputs are used.
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 2377814 Photo


Registered User
45 posts

Hi Eric, thank you for your reply.
I haven't published the form yet.

It will have name, email address, message, and then a box for them to enter a numerical amount [Amount], after this I need it to show the calculated price, then an order button.

Whatever amount they enter needs to be rounded up to the nearest 1,000 and then divided by 1000 and multiplied by 14 to give the calculated price (equalling £14 per one thousand or part thereof) Which they then pay in the next step.

E.g 800 would be rounded to 1000 and cost £14
1,221 would be rounded to 2000 and cost £28
4,020 would be rounded to 5,000 and cost £70

I hope that is a good explanation
User 187934 Photo


Senior Advisor
20,190 posts

Perhaps.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script>var jQ = $.noConflict(true);
jQ(document).ready(function(){
// ver 1
jQ('input[name="total"]').prop('readonly', true);
jQ('input[name="amount"]').keyup(function(){
var RAmount = Math.ceil(jQ(this).val()/1000)*1000;
var FinRAmount = (RAmount/1000)*14;
jQ('input[name="total"]').val(FinRAmount.toFixed(0));
});
});</script>

Assumes inputs named amount and total
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 2377814 Photo


Registered User
45 posts

Thank you so much Eric for your help.

Im sorry, Im rather more rusty with this than I thought :/. There is a number field in the form named [Amount] in which the customer is to type their amount.

I have entered the code you have provided into a HTML Element but it is displaying in the previewed form as "your html element"

and I don't know what element type i should select for [Total] to display the total the customer will pay before they click submit which will be calculated from your code
User 187934 Photo


Senior Advisor
20,190 posts

Add a number element to you form with the name Total
Past the code below into a html element on your form.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var jQ = $.noConflict(true);
jQ(document).ready(function(){
// ver 2
jQ('input[name="Total"]').prop('readonly', true);
jQ('input[name="Amount"]').keyup(function(){
var RAmount = Math.ceil(jQ(this).val()/1000)*1000;
var FinRAmount = (RAmount/1000)*14;
jQ('input[name="Total"]').val(FinRAmount.toFixed(0));
});
});</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 379556 Photo


Registered User
1,535 posts

M G wrote:
I have entered the code you have provided into a HTML Element but it is displaying in the previewed form as "your html element"

As may have been discovered by now, Eric's code is to be entered in the Content box of the HTML Properties tab instead of the code that is there by default, and not in addition to it. One must also not click on the '+' next to the '?' immediately below the Content box after adding Eric's code.

This help page gives details about using the HTML element in Web Form Builder.

Frank
User 2377814 Photo


Registered User
45 posts

Thank you so very much :) for your time and your help it is much appreciated

If I wanted a £ sign to show before the calculated total where would I insert this in the code?
so instead of generating 14.00 it shows as £14.00
User 187934 Photo


Senior Advisor
20,190 posts

The Total input will need to be a text input.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var jQ = $.noConflict(true);
jQ(document).ready(function(){
// ver 2
jQ('input[name="Total"]').prop('readonly', true);
jQ('input[name="Amount"]').keyup(function(){
var RAmount = Math.ceil(jQ(this).val()/1000)*1000;
var FinRAmount = (RAmount/1000)*14;
jQ('input[name="Total"]').val('£' + FinRAmount.toFixed(0));
});
});</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

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.