/    Sign up×
Community /Pin to ProfileBookmark

JS Help Quote Calculator

Hello,

I need some help with a head ache quote calculator. I was asked to redesign a website for a client which is all good and fine but they had a price quote calculator that they also needed updated. Here was the issue with the old calculator they had: it was made in flash and very difficult for them to edit. Plus for whatever reason it had not been working properly. It was designed over 6 years ago by a guy they can’t get in contact with anymore. So what they wanted was a new calculator that they could go in and edit without a headache, something that they could understand what to change if they needed (for instance cost of materials is always fluctuating). I took a look at the flash file but it wasn’t very helpful in designing this new calculator. So I figured it wouldn’t be too hard, and I’d learn from it as well so I took the job… May have bitten off a bit more than I can chew but I’m determined at this point to do this so I can learn, I would just like a little help. I’ve come up with two ways to do this, but I think for my sake and the clients sake the second one may be easier to work with.

First option:

[code]!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Untitled Document</title>
<script type=”text/javascript”>

var categories = [];
categories[“startList”] = [“Closed Louver”,”Open Louver”, “Raised Panel”,”Board and Batten”,”Bermuda”]
categories[“Closed Louver”] = [“None – 1 Panel”,”50/50 – 2 panel”,”60/40 – Larger top panel”,”40/60 – Larger bottom panel”,”33/33/33 – 3 panel”];
categories[“None – 1 Panel”] = [“Western Red Cedar”];
categories[“50/50 – 2 panel”] = [“Western Red Cedar”];
categories[“60/40 – Larger top panel”] = [“Western Red Cedar”];
categories[“40/60 – Larger bottom panel”] = [“Western Red Cedar”];
categories[“33/33/33 – 3 panel”] = [“Western Red Cedar”];
categories[“Western Red Cedar”] = [“1 3/8 inch”];
categories[“1 3/8 inch”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“0/8”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“1/8”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“1/4”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“3/8”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“1/2”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“5/8”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“3/4”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8”];
categories[“7/8”] = [“0/8″,”1/8″,”1/4″,”3/8″,”1/2″,”5/8″,”3/4″,”7/8″];

var nLists = 6; // number of select lists in the set

function fillSelect(currCat,currList){
var step = Number(currList.name.replace(/D/g,””));
for (i=step; i<nLists+1; i++) {
document.forms[‘quotecalculator’][‘List’+i].length = 1;
document.forms[‘quotecalculator’][‘List’+i].selectedIndex = 0;
}
var nCat = categories[currCat];
for (each in nCat) {
var nOption = document.createElement(‘option’);
var nData = document.createTextNode(nCat[each]);
nOption.setAttribute(‘value’,nCat[each]);
nOption.appendChild(nData);
currList.appendChild(nOption);
}
}

function init() {
fillSelect(‘startList’,document.forms[‘quotecalculator’][‘List1’])
}

navigator.appName == “Microsoft Internet Explorer” ? attachEvent(‘onload’, init, false) : addEventListener(‘load’, init, false);

</script>
</head>

<body>
<form name=”quotecalculator” action=””>
<select name=’List1′ onchange=”fillSelect(this.value,this.form[‘List2′])”>
<option selected>Select A Shutter Style</option>
</select>
&nbsp;
<select name=’List2’ onchange=”fillSelect(this.value,this.form[‘List3′])”>
<option selected>Mid Rail Divider</option>
</select>
&nbsp;
<select name=’List3’ onchange=”fillSelect(this.value,this.form[‘List4′])”>
<option selected >Material</option>
</select>
&nbsp;
<select name=’List4’ onchange=”fillSelect(this.value,this.form[‘List5′])”>
<option selected >Thickness</option>
</select>
<br />
<br />
<br />
<label>Quantity
<input type=”text” name=”Quantity” id=”Quantity” />
</label>
&nbsp;
<label>Width
<input type=”text” name=”Width” id=”Width” />
</label>
&nbsp;
<select name=’List5’ onchange=”fillSelect(this.value,this.form[‘List6′])”>
<option selected >Increments (in inches)</option>
</select>
x
<label>Height
<input type=”text” name=”Height” id=”Height” />
</label>
<p>&nbsp;
<select name=’List6’ onchange=”getValue(this.value, this.form[‘List2’].value,
this.form[‘List1’].value)”>
<option selected >Increments (in inches)</option>
</select>
<br />
<br />
<br />
</p>
</form>
</body>
</html>[/code]

If possible I would like to have the first option change all the other drop down options and not just the next one (then the next one, then the next one…).

I’ve tried a few different ways but nothing seems to work, for example:

[code]<select name=’List1′ onchange=”fillSelect(this.value,this.form[‘List2’, ‘List3’, ‘List4’])”>
<option selected>Select A Shutter Style</option>[/code]

I feel like I am going to run into problems doing it this way say if open louver and closed louver have the same mid rail divider options but the materials are different.

My second option is having the user select what style they want first on an html page and it brings them to a calculator specific to that style. So for closed louver:

[code]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Untitled Document</title>

</head>

<body>
<form id=”closedlouver” name=”closedlouver” method=”post” action=””>
<label>Mid Rail Divider
<select name=”midraildivider” id=”Mid Rail Divider”>
<option selected=”selected”>Select One</option>
<option>None – 1 Panel</option>
<option>50/50 – 2 Panel</option>
<option>60/40 – Larger Top Panel</option>
<option>40/60 – Larger Bottom Panel</option>
<option>33/33/33 – 3 Panel</option>
</select>
</label>
&nbsp;
&nbsp;
&nbsp;
<label>Material
<select name=”material” id=”material”>
<option selected=”selected”>Select One</option>
<option>Western Red Cedar</option>
</select>
</label>
&nbsp;
&nbsp;
&nbsp;
<label>Thickness
<select name=”thickness” id=”thickness”>
<option>Select One</option>
<option>1 3/8&quot;</option>
</select>
</label>
<br /><br />
<label>Quantity
<input type=”text” name=”quantity” id=”quantity” />
</label>
<br /><br />
<label>Width
<input type=”text” name=”width” id=”width” />
</label>
&nbsp;
&nbsp;
&nbsp;
<label>Increments
<select name=”widthincrements” id=”widthincrements”>
<option>Select One</option>
<option>0/8&quot;</option>
<option>1/8&quot;</option>
<option>1/4&quot;</option>
<option>3/8&quot;</option>
<option>1/2&quot;</option>
<option>5/8&quot;</option>
<option>3/4&quot;</option>
<option>7/8&quot;</option>
</select>
</label>
&nbsp;
&nbsp;
&nbsp;
<label>Height
<input type=”text” name=”height” id=”height” />
</label>
&nbsp;
&nbsp;
&nbsp;
<label>Increments
<select name=”heightincrements” id=”heightincrements”>
<option>Select One</option>
<option>0/8&quot;</option>
<option>1/8&quot;</option>
<option>1/4&quot;</option>
<option>3/8&quot;</option>
<option>1/2&quot;</option>
<option>5/8&quot;</option>
<option>3/4&quot;</option>
<option>7/8&quot;</option>
</select>
</label>
<br /><br />
Add-Ons (per pair)
<br /><br />
<label>
<input type=”checkbox” name=”priming” id=”priming” />
Priming $50</label>
&nbsp;
&nbsp;
&nbsp;
<input type=”checkbox” name=”fauxtiltrods” id=”fauxtiltrods” />
Faux Tilt Rods $50</label>
&nbsp;
&nbsp;
&nbsp;
<input type=”checkbox” name=”coppercaps” id=”coppercaps” />
Copper Caps $70</label>
<br /><br />
<input type=”checkbox” name=”horns” id=”horns” />
Horns $50</label>
&nbsp;
&nbsp;
&nbsp;
<input type=”checkbox” name=”arches” id=”arches” />
Arches $150</label>
<br /><br /><br /><br />
<input type=”submit” name=”calculate” id=”calculate” value=”Calculate” />
</form>
</body>
</html>[/code]

Now for both of these heres the calculation I’m working with and I have no idea how to incorporate this in the js.

15” x 55” = 825 x 2 = 1650 divided by 144 = 11.46sf x $24 = $275.04/pair

W x H = whatevernumber x 2 = whatevernumber / 144 = numberofsquarefeet x costofstyle(flat rate for example closed louver is $24) = total price per pair.

All I need to know is how to calculate the total based on the specs the customer types in.

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMay 16.2011 — Doing the calculations won't be hard, but I'm a little confused about the rest of your form: (Using last HTML posting)

  • 1. Are the "Mid Rail Divider", "Material" and "Thickness" and "Quantity" supposed be be part of the calculation?


    If so, where do they fit into the formula?


  • 2. What relationship are the "Increment" to the calculation? And what is 0/8" supposed to represent?


  • 3. How are the "Add-Ons" factored into the equation?
  • Copy linkTweet thisAlerts:
    @melbahtoastauthorMay 16.2011 — Thanks for your reply JMRKER,

  • 1. No they are not part of the calculation.


  • 2. Increment is not part of the calculation either, it's for the guys at the shop when they make cuts. 0/8 is 0. But all info is linked back to the database so they can see the specs before they make the shutters.


  • 3. Add-ons are factored in by price of item then price per pair.


  • However, I was able to figure this one out (it took me all day) but it's working properly. But any time on better ways to layout options are still appreciated

    View calculator and code http://nuinnovisions.com/shutterquotecalculator.html

    Thanks,

    Melissa
    Copy linkTweet thisAlerts:
    @melbahtoastauthorMay 16.2011 — Tried replying didn't show up...

  • 1. Those do not effect the calculation


  • 2. Again, those do not effect the calculation. When the form is submitted it links back to a data base so the guys can get the specs before they start making the shutters. 0/8 = 0


  • 3. The add-ons have different pricing. The are calculated to the total per pair and total per quantity.


  • I've come up with a solution that works so if anyone wants to look, comment, give suggestions, or use the code for yourself it can be found here:

    http://www.nuinnovisions.com/shutterquotecalculator.html
    Copy linkTweet thisAlerts:
    @JMRKERMay 16.2011 — I have not checked your formulas, but I would remove the quotes (") around this:
    <i>
    </i>var priceperpair = width * height * "2" / "144";

    var priceperquantity = width * height * "2" / "144" * quantity;

    because it appears you are trying to multiply a number by a string. May work, but somewhat confusing.

    And it definitely won't work right if you try latter to add a "string"
    ×

    Success!

    Help @melbahtoast spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...