Created
June 10, 2019 01:50
-
-
Save steven-miller/39b0901c00cde6edca80b338302feeed to your computer and use it in GitHub Desktop.
HubSpot customized form for price estimates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Answer the questions below to get a good idea of the cost to clean your house each month in the Boston area (disclaimer below)</p> | |
<script> | |
/* | |
List of elements | |
options for those elements: | |
what_size_is_your_home_ | |
0 = Studio | |
1 = 1 Bedroom | |
2 = 2 Bedroom | |
3 = 3+ Bedroom | |
how_many_bathrooms_are_in_your_home_ | |
1 | |
1.5 | |
2 | |
2.5 | |
3 = 3+ | |
with_how_many_other_people_would_you_split_the_cost_of_cleaning | |
0 = None | |
1 | |
2 | |
3 | |
4 | |
5 = 5+ | |
how_frequently_would_your_home_be_cleaned_ | |
4 = Once per week | |
2 = Twice per month | |
1 = Once per month | |
calculator_result | |
Math | |
1 hr base + 1 for each room | |
+ 1 hr for each room | |
split cost (divide by people + 1) | |
multiply by frequency | |
*/ | |
var result = 0; | |
function calculateResult(){ | |
// get the selected values from the form | |
var size = parseInt($('select[name="what_size_is_your_home_"] option:selected').val()); | |
var bathroom = parseInt($('select[name="how_many_bathrooms_are_in_your_home_"] option:selected').val()); | |
var people = parseInt($('select[name="with_how_many_other_people_would_you_split_the_cost_of_cleaning"] option:selected').val()); | |
var frequency = parseInt($('select[name="how_frequently_would_your_home_be_cleaned_"] option:selected').val()); | |
// math it out | |
result = parseInt((35 * (1 + size + bathroom) * frequency) / (people + 1)); | |
// write the result into the hidden result field in the form ... | |
$('input[name="calculator_result"]').val(result); | |
// ... and also display it on the page | |
document.getElementById("resultContainer").innerHTML= '$ ' + result; | |
} | |
</script> | |
<!--[if lte IE 8]> | |
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script> | |
<![endif]--> | |
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script> | |
<script> | |
hbspt.forms.create({ | |
portalId: '', | |
formId: '', | |
onFormSubmit($form, ctx){ | |
calculateResult() | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment