I'm a newbie here and was wondering if there are any scripts available to do some math calculations within a form that I can then submit to a product database. My website is going to be based on custom sized shipping boxes.
What I am looking to do is have a user input the Length, Width and Depth of the shipping box as well as material and quantity into text boxes and select boxes. I already know the math that I need to use in order to figure out the cost based upon the user input but I don't have a lot of knowledge with javascript. I know HTML pretty well and have edited JS in the past, I just don't have enough experience to write it from scratch. Can anyone point me in the right direction to save some time?
thanks,
Matt
What I am looking to do is have a user input the Length, Width and Depth of the shipping box as well as material and quantity into text boxes and select boxes. I already know the math that I need to use in order to figure out the cost based upon the user input but I don't have a lot of knowledge with javascript. I know HTML pretty well and have edited JS in the past, I just don't have enough experience to write it from scratch. Can anyone point me in the right direction to save some time?
thanks,
Matt
Hi Matt,
You will need a JavaScript snippet to do this. It's going to be custom code but isn't too difficult. If you post the HTML from your form (or the ids of the elements we can create a basic version for you to work from).
Bob
You will need a JavaScript snippet to do this. It's going to be custom code but isn't too difficult. If you post the HTML from your form (or the ids of the elements we can create a basic version for you to work from).
Bob
Thanks Bob,
I already figured out the basics though... I was anxious to get started and I figured I could use a refresher in javascript so I did some research last night. Here is what I came up with for a first shot:
Works pretty well for my first shot. Now I just need to implement it into Chronoforms and set some validations then have it write to a database. I think I'll use some different ids for the elements too so it isn't as confusing to figure which is which. I'm sure I will have some questions in the near future for you :wink:
Thanks again,
Matt
I already figured out the basics though... I was anxious to get started and I figured I could use a refresher in javascript so I did some research last night. Here is what I came up with for a first shot:
<html>
<head>
<p>RSC 275#C
<p>
<SCRIPT language = JavaScript>
function calculate() {
L = document.frmOne.txtlength.value
W = document.frmOne.txtwidth.value
D = document.frmOne.txtdepth.value
L = Number(L)
W = Number(W)
D = Number(D)
d = 6
X = (L + W)*2 + 2.25
Y = W + D + .6875
a = Math.floor(65/Y)
b = Math.floor(119/X)
Z = a * b
c = d/Z
document.frmOne.txttotal.value = X
document.frmOne.txttotal2.value = Y
document.frmOne.txttotal3.value = Z
document.frmOne.txttotal4.value = a
document.frmOne.txttotal5.value = b
document.frmOne.txttotal6.value = (c.toFixed(2))
}
</SCRIPT>
</head>
<FORM NAME = frmOne>
Length: <INPUT TYPE = Text NAME = txtlength SIZE = 5 value ="">
Width: <INPUT TYPE = Text NAME = txtwidth SIZE = 5 value ="">
Depth: <INPUT TYPE = Text NAME = txtdepth SIZE = 5 value ="">
<P>
120" Dimension: <INPUT TYPE = Text NAME = txttotal SIZE = 5 value = "">
<P>
<P>
66" Dimension: <INPUT TYPE = Text NAME = txttotal2 SIZE = 5 value = "">
<P>
<P>
Total pcs Per Sheet: <INPUT TYPE = Text NAME = txttotal3 SIZE = 5 value = "">
<P>
<P>
How Many in 66" Direction?: <INPUT TYPE = Text NAME = txttotal4 SIZE = 5 value = "">
<P>
<P>
How Many in 120" Direction?: <INPUT TYPE = Text NAME = txttotal5 SIZE = 5 value = "">
<P>
<P>
Cost per piece: $ <INPUT TYPE = Text NAME = txttotal6 SIZE = 5 value = "">
<P>
<Input Type = Button NAME = b2 VALUE = "Calculate Total" onClick = calculate() >
</FORM>
</html>Works pretty well for my first shot. Now I just need to implement it into Chronoforms and set some validations then have it write to a database. I think I'll use some different ids for the elements too so it isn't as confusing to figure which is which. I'm sure I will have some questions in the near future for you :wink:
Thanks again,
Matt
This topic is locked and no more replies can be posted.
