View Full Version : Order Form w/current options live total
williamsun
07-26-2012, 10:03 PM
Hello, I am new here so please bear with me while I get the rhythm of the forum.
I'm not a programmer, but not an html newbie either. I would like some advice on which direction to go. I am a surfboard manufacturer and would like to add an order form with a live total of current options selected -- like a different base price for certain types of foam and resin, special glassing, air brush paint job, number and types of fins, etc.
Which would be the best direction to go, with something that I could edit & modify to suit my needs......., JavaScript, Flash (I have Macromedia Flash MX 2002 and just started trying to learn it), or something like ZenCart on Godaddy hosting?
Thanks for any constructive input.
bernie1227
07-26-2012, 10:45 PM
this ("http://wufoo.com/gallery/)
Has some free template forms which you can modify
williamsun
07-27-2012, 07:01 AM
Thank you. I have been checking out some basic drop down list javascript forms like:
http://pjnicholson.com/htmlguide/orderform.htm
http://www.jdstiles.com/java/dualform.html
...and several others that might be a good start to build on, if javascript is the way to go. Although those would be a lot of work to adapt all the options available, and are just a base price + quantity forms.
I should have mentioned that I'm looking for a wizard type of interface (optionally - with an image that might change to reflect the users choice - adding or subtracting a transparent overlay of a .gif or .png image), but it's not a deal breaker. I would prefer this because there could be a total of 100 options and I don't want to give novice surfers information overload, just something between emailing us and discussing back and forth what they want, and an html order form I have built already with all options available that uses a php form emailer through godaddy that I use to host my site.
Do you still think javascript is the way to go for my situation, or should I try to bang out something in the prehistoric flash software I have, or would there be too many compatibility issues to deal with, and maybe over my head? I know Macromedia Flash MX 2002 is VERY old, and I don't know programming. I'm pretty good with html, css, and graphics, but not programming.
bernie1227
07-27-2012, 07:20 AM
well basically, the form should be written in html and css (as in the display), but for the client side functionality, eg telling them they haven't filled one of the boxes, you'd want javascript, but as a quick question, are you planning to have the form submitted to a database? or emailed to you?
williamsun
07-27-2012, 12:51 PM
It would be emailed to me at first, like I have now, but later I would like to integrate it into an online shopping cart type of deal. That is why I mentioned ZenCart at first, it looks the most promising, however I am open to suggestions.
I have an html form now (not yet on the site) with a javascript validator and noscript to hide the whole form if javascript is disabled. I could make a second stripped down version of my current form for a more simple interface for inexperienced users. I would still have the issue of a running total unless I could figure out how to add the javascript code for it to what I have now.
How can I show or change an image (surfboard w/options chosen) by clicking on radio button selections?
bernie1227
07-28-2012, 09:12 AM
Just as a question, how are you getting it emailed to you? Just a comment, it may be easier (and more customisable) to write some php to submit the form to the database, so that you don't have to read 50 emails a day or whatever.
Here is an example of changing the image when a checkbox is ticked.
<html>
<head>
<title>Williamsun's extremely awesome and cheap surfboards</title>
<script type="text/javascript">
function processCheckbox(checkbox) {
if (checkbox.checked) {
image.src = "awesomesurfboard1.png";
} else {
image.src = "awesomesurfboard2.png";
}
}
</script>
</head>
<body>
<img src="awesomesurfboard2.png" id="image">
<form name="theform">
<input type="checkbox">surfboard1</input>
</form>
</body>
</html>
Hope you like the title of the example page :p
williamsun
07-28-2012, 03:58 PM
Just as a question, how are you getting it emailed to you? Just a comment, it may be easier (and more customisable) to write some php to submit the form to the database, so that you don't have to read 50 emails a day or whatever.
Hope you like the title of the example page :p
Yeah, that was pretty good. :D
A php sorting database is a good idea, but I haven't gotten that far yet.
Godaddy has a basic form mailer that I use, and I just prefix form element names with letters/numbers so the values come in a logical list order.
The complicating problem I have with the running total or auto sum is, everything keys off of the length set by two drop down lists - feet and inches - then mostly radio buttons to determine options, so if a user doesn't make a selection the default is selected. All of the auto sum total scripts I found are single selection drop down lists or check boxes. I haven't found anything that combines them all like I need. I may have to abandon this and go to plan B. Or c or d or e.
A flash wizard interface to do it all might be just what I need, but it's way over my head to do something like that at my (non)level of expertise.
I think this may be a dead end.
bernie1227
07-30-2012, 09:59 AM
wait, if I'm reading this correctly (which I might not be :p), the problem is it is a preset form, so you don't have a good level of customisation? Is that the problem?
williamsun
07-30-2012, 12:00 PM
I'm not sure exactly how you mean. The form is finished, I built it from scratch. It's very similar in function to a couple forms I have done before for the same thing on a previous site. I have the look and feel customized the way I want, just no totaling function. Someone fills out the form with selected options and custom textarea fields and the form mailer sends it to me as an itemized list with options and descriptions.......I email them back to confirm order and total price, and arrange 50% deposit to start building.
A running total or auto sum field displayed above the submit button for instance, would be very intuitive for the customer and save time and effort for both of us. I would really like to find a way to do this, but I don't know if it is workable.
bernie1227
07-30-2012, 08:09 PM
I see what you mean now, an autosum button is workable, I will try to fix you up an example of one.
williamsun
07-30-2012, 09:19 PM
Really? Wow!
I don't remember if I mentioned this so I'll run through so you'll see the problems that might make it tough.
Everything on the form (and the base price) is based on the length, two drop down lists, feet and inches. Mostly radio buttons that are just choice selections but don't affect the price. I can have a hidden value of the inches in decimals, so for instance, a 6'1" would be 6.0833 . It would need to add the two drop down lists like I mentioned multiplied by a base price factor, then the two or three radio buttons that do effect the price and I have broken down to $ per board foot, and maybe another one that may add a fixed amount if selected to that total.
This just seems ridiculously complicated even to me, that is why I am kind of leery of finding a working solution.
If you or someone can get close, I might be able to adapt it. And you would have my never ending thanks!
bernie1227
07-31-2012, 10:45 AM
i have finished writing a sample, and it works. hopefully it wont be too complicated for you. Forgive me for size and price estimates, as i have no idea about surfboards :p
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Surfboard Form</title>
<script type="text/javascript">
//Set up an associative array
var surf_prices = new Array();
surf_prices["good"]=100;
surf_prices["pretty"]=200;
surf_prices["very"]=300;
surf_prices["epic"]=1000;
//Set up an associative array
//We use this this array when the user selects a size from the form
var size_prices= new Array();
size_prices["None"]=0;
size_prices["5 ft"]=100;
size_prices["6 ft"]=150;
size_prices["7 ft"]=200;
size_prices["8 ft"]=250;
size_prices["9 ft"]=300;
// getsurfboardPrice() finds the price based on the size of the Surfboard.
function getsurfboardPrice()
{
var surfboardPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the Surfboard the user Chooses name=selectedsurf":
var selectedsurf = theForm.elements["selectedsurf"];
//Here since there are 4 radio buttons selectedsurf.length = 4
//We loop through each radio buttons
for(var i = 0; i < selectedsurf.length; i++)
{
//if the radio button is checked
if(selectedsurf[i].checked)
{
//set surfboardPrice to value of elected radio button
// using the surf_prices array
//We get the selected Items value
surfboardPrice = surf_prices[selectedsurf[i].value];
//If we get a match then we break out of this loop
//No reason to continue if we get a match
break;
}
}
//return surfboardPrice
return surfboardPrice;
}
//This function finds the size price based on the
//drop down selection
function getSurfSize()
{
var surfSizePrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the select id="size"
var selectedsize = theForm.elements["size"];
//set Surfboardsize Price equal to value user chose
surfSizePrice = size_prices[selectedsize.value];
// return surfSizePrice
return surfSizePrice;
}
//footstrapPrices() finds foot strap price based on a check box selection
function footstrapPrices()
{
var footstrapPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeFootStrap"
var includeFootStrap = theForm.elements["includeFootStrap"];
//If they checked the box set footstrapPrice to 5
if(includeFootStrap.checked==true)
{
footstrapPrice=50;
}
//return footstrapPrice
return footstrapPrice;
}
function insciptionPrice()
{
//This local variable will be used to decide whether or not to charge for the inscription
//If the user checked the box this value will be 20
//otherwise it will remain at 0
var inscriptionPrice=0;
//Get a refernce to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeinscription"
var includeInscription = theForm.elements["includeinscription"];
//If they checked the box set inscriptionPrice to 20
if(includeInscription.checked==true){
inscriptionPrice=20;
}
//return inscription price
return inscriptionPrice;
}
function calculateTotal()
{
//total price by calling functions
var SurfboardPrice = getsurfboardPrice() + getSurfSize() + footstrapPrices() + insciptionPrice();
//display result
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price For the Surfboard $"+SurfboardPrice;
}
function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
</script>
</head>
<body onload='hideTotal()'>
<div id="wrap">
<form action="" id="surfboardForm" onsubmit="return false;">
<div>
<div class="cont_order">
<fieldset>
<legend>Get a Surfboard!</legend>
<label >Type of Surfboard:</label><br />
<label class='radiolabel'><input type="radio" name="selectedsurf" value="good" onclick="calculateTotal()" />good surfboard ($100)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="pretty" onclick="calculateTotal()" />pretty good surfboard($200)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="very" onclick="calculateTotal()" />very good surfboard($300)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="epic" onclick="calculateTotal()" />epic surfboard ($1000)</label><br/>
<br/>
<label>size</label>
<select id="size" name='size' onchange="calculateTotal()">
<option value="None">Select size</option>
<option value="5 ft">5 ft($100)</option>
<option value="6 ft">6 ft($150)</option>
<option value="7 ft">7 ft($200)</option>
<option value="8 ft">8 ft($250)</option>
<option value="9 ft">9 ft($300)</option>
</select>
<br/>
<p>
<label for='includeFootStrap' class="inlinelabel">Include epic Footstrap($50)</label>
<input type="checkbox" id="includeFootStrap" name='includeFootStrap' onclick="calculateTotal()" />
</p>
<p>
<label class="inlinelabel" for='includeinscription'>Include Inscription($20)</label>
<input type="checkbox" id="includeinscription" name="includeinscription" onclick="calculateTotal()" />
<input type="text" id="theinscription" name="theinscription" value="Enter Inscription" />
</p>
<div id="totalPrice"></div>
</fieldset>
</div>
<input type='submit' id='submit' value='Submit' onclick="calculateTotal()" />
</div>
</form>
</div><!--End of wrap-->
</body>
</html>
williamsun
07-31-2012, 02:54 PM
:eek:
Thank you thank you thank you ! ! !
I need to get back out and get a skil saw in my hands and finish the new factory for now, but I'll take a look and try some stuff with that this evening.
I'm sure I'll have many more questions. :D
Thanks again man!
williamsun
08-01-2012, 06:29 PM
Is it adding 'surf_prices' and 'size_prices' to get the variable 'selectedsurf' and attaching that value to the new variable 'surfboardPrice' ?
With 'selectedsurf.length' being the number of radio buttons of surfboard types?
williamsun
08-01-2012, 08:05 PM
Maybe it's better if I show what I'm trying to do with fictional prices.
//Set up an associative array
var ft_price = new Array();
ft_price["05ft"]=400.00;
ft_price["06ft"]=400.00;
ft_price["07ft"]=450.00;
ft_price["08ft"]=500.00;
ft_price["09ft"]=550.00;
ft_price["10ft"]=600.00;
//Set up an associative array
//We use this this array when the user selects a size from the form
var in_price= new Array();
in_price["None"]=0;
in_price["00in"]=00.00;
in_price["01in"]=04.17;
in_price["02in"]=08.34;
in_price["03in"]=12.50;
in_price["04in"]=16.67;
in_price["05in"]=16.67;
in_price["06in"]=25.00;
in_price["07in"]=29.17;
in_price["08in"]=33.34;
in_price["09in"]=37.50;
in_price["10in"]=41.67;
in_price["11in"]=45.84;
ft_price + in_price = baseprice (the total of the two drop down lists, feet and inches. This is more important than the 10 radio buttons selecting 'boardtype'.)
...and then use the baseprice to add to or subtract from for 'surfboardprice' or 'totalprice'. Something like that.
I don't want to be headed in the wrong direction and mess it up even worse, and waste even more of your time.
bernie1227
08-01-2012, 08:53 PM
So what is happening here, is that the arrays are being referenced in the functions; getsurfboardPrice and getSizePrice respectively, then those two functions are added together along With the foot strap and the inscription to get the total price.
Just as a suggestion, when you want to replace array names or variable names, I suggest you actually do a search and replace, because this means that you win't have to go through and change them individually and there is no chance of you missing any of them.
williamsun
08-01-2012, 10:01 PM
I appreciate your help explaining it to me. - I am using search & replace.
So if a customer chose a special cloth in the middle of the form that added $7 per board foot plus X-cents per extra inch, and keyed off of the feet and inches already selected, how would I do that? Or would it overly complicate it for me.
bernie1227
08-02-2012, 01:09 AM
Sorry, I don't really understand, so do want it to be a dropdown box or radio buttons to select cloth for extra price?
williamsun
08-02-2012, 02:41 AM
Yes you did. The cloth question is new. I just thought I'd ask while I was messing with this deal.
I could copy and modify the two arrays, functions, variables, & price values, but then that would mean 2 more drop down lists for feet and inches of cloth. That would be too clumsy and open to inconsistent settings with the board feet and inches already selected. I would rather use text specifying the extra cost and the customer and I calculate it manually.
What I was wondering is if there is a way to use the board feet and inches already selected and somehow redefine the output value to the different price value, then add that along with the others already being added for the totalprice. It would be a radio button for the special cloth. Either yes or no (the default).
Is this possible?
bernie1227
08-02-2012, 02:51 AM
Oh ok, that makes sense now, thanks for clarifying, what you'd want to do, is create a new function to check whether the user wanted the special cloth, in which you'd check to see if the user checked a radio button, like I did elsewhere in the script, and then in the function calculateTotal you would add the special cloth function to the final total, in which all the other functions are being added together.
bernie1227
08-02-2012, 03:04 AM
Erm, if I'm right, this might be something like what you want (modified original script):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Surfboard Form</title>
<script type="text/javascript">
//Set up an associative array
var surf_prices = new Array();
surf_prices["good"]=100;
surf_prices["pretty"]=200;
surf_prices["very"]=300;
surf_prices["epic"]=1000;
//Set up an associative array
//We use this this array when the user selects a size from the form
var size_prices= new Array();
size_prices["None"]=0;
size_prices["5 ft"]=100;
size_prices["6 ft"]=150;
size_prices["7 ft"]=200;
size_prices["8 ft"]=250;
size_prices["9 ft"]=300;
// getsurfboardPrice() finds the price based on the size of the Surfboard.
function getsurfboardPrice()
{
var surfboardPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the Surfboard the user Chooses name=selectedsurf":
var selectedsurf = theForm.elements["selectedsurf"];
//Here since there are 4 radio buttons selectedsurf.length = 4
//We loop through each radio buttons
for(var i = 0; i < selectedsurf.length; i++)
{
//if the radio button is checked
if(selectedsurf[i].checked)
{
//set surfboardPrice to value of elected radio button
// using the surf_prices array
//We get the selected Items value
surfboardPrice = surf_prices[selectedsurf[i].value];
//If we get a match then we break out of this loop
//No reason to continue if we get a match
break;
}
}
//return surfboardPrice
return surfboardPrice;
}
//This function finds the size price based on the
//drop down selection
function getSurfSize()
{
var surfSizePrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the select id="size"
var selectedsize = theForm.elements["size"];
//set Surfboardsize Price equal to value user chose
surfSizePrice = size_prices[selectedsize.value];
// return surfSizePrice
return surfSizePrice;
}
//footstrapPrices() finds foot strap price based on a check box selection
function footstrapPrices()
{
var footstrapPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeFootStrap"
var includeFootStrap = theForm.elements["includeFootStrap"];
//If they checked the box set footstrapPrice to 5
if(includeFootStrap.checked==true)
{
footstrapPrice=50;
}
//return footstrapPrice
return footstrapPrice;
}
function clothPrices()
{
var clothPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeCloth"
var includeCloth = theForm.elements["includeCloth"];
//If they checked the box set cloth to 50
if(includeCloth.checked==true)
{
clothPrice=50;
}
//return clothPrice
return clothPrice;
}
function insciptionPrice()
{
//This local variable will be used to decide whether or not to charge for the inscription
//If the user checked the box this value will be 20
//otherwise it will remain at 0
var inscriptionPrice=0;
//Get a refernce to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeinscription"
var includeInscription = theForm.elements["includeinscription"];
//If they checked the box set inscriptionPrice to 20
if(includeInscription.checked==true){
inscriptionPrice=20;
}
//return inscription price
return inscriptionPrice;
}
function calculateTotal()
{
//total price by calling functions
var SurfboardPrice = getsurfboardPrice() + getSurfSize() + footstrapPrices() + insciptionPrice() + [color="red"]clothPrices();[/red]
//display result
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price For the Surfboard $"+SurfboardPrice;
}
function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
</script>
</head>
<body onload='hideTotal()'>
<div id="wrap">
<form action="" id="surfboardForm" onsubmit="return false;">
<div>
<div class="cont_order">
<fieldset>
<legend>Get a Surfboard!</legend>
<label >Type of Surfboard:</label><br />
<label class='radiolabel'><input type="radio" name="selectedsurf" value="good" onclick="calculateTotal()" />good surfboard ($100)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="pretty" onclick="calculateTotal()" />pretty good surfboard($200)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="very" onclick="calculateTotal()" />very good surfboard($300)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="epic" onclick="calculateTotal()" />epic surfboard ($1000)</label><br/>
<br/>
<label>size</label>
<select id="size" name='size' onchange="calculateTotal()">
<option value="None">Select size</option>
<option value="5 ft">5 ft($100)</option>
<option value="6 ft">6 ft($150)</option>
<option value="7 ft">7 ft($200)</option>
<option value="8 ft">8 ft($250)</option>
<option value="9 ft">9 ft($300)</option>
</select>
<br/>
<p>
<label for='includeFootStrap' class="inlinelabel">Include epic Footstrap($50)</label>
<input type="checkbox" id="includeFootStrap" name='includeFootStrap' onclick="calculateTotal()" />
</p>
<br/>
<p>
<label for='includeCloth' class="inlinelabel">Include cool cloth($50)</label>
<input type="checkbox" id="includeCloth" name='includeCloth' onclick="calculateTotal()" />
</p>
<p>
<label class="inlinelabel" for='includeinscription'>Include Inscription($20)</label>
<input type="checkbox" id="includeinscription" name="includeinscription" onclick="calculateTotal()" />
<input type="text" id="theinscription" name="theinscription" value="Enter Inscription" />
</p>
<div id="totalPrice"></div>
</fieldset>
</div>
<input type='submit' id='submit' value='Submit' onclick="calculateTotal()" />
</div>
</form>
</div><!--End of wrap-->
</body>
</html>
Changes are in red
williamsun
08-02-2012, 03:06 AM
Ok, but what I'm drawing a blank on, is if the price value is defined in the first two arrays for board feet and inches, how would I reuse the feet and inches but change the price value to the cloth feet and inches price without doing two new arrays with the cloth prices.
For instance, with the values I used for my post, a 6'1" board would have a base price 404.17, so how could I reuse the 6'1" length selected for that but use the cloth value of 042.08 (for 6'1", different for other lengths) to be added along with the others if the special cloth radio button is selected.
Did that make sense?
EDIT:
You posted while I was typing mine but I think my question is still valid considering the cloth value is not a specific amount, but depending the feet and inches already selected.
bernie1227
08-02-2012, 03:33 AM
What you could do, is set something up within the GetsurfSize function where, if the button is checked, it adds the price of the cloth depending on which size was selected.
bernie1227
08-02-2012, 08:52 AM
Okey doke, I've fixed you up a version 3.0, in which, when the cloth checkbox is checked, the default price is 50$, which changes when you change the size of the surfboard. I've done this using a switch statement:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Surfboard Form</title>
<script type="text/javascript">
//Set up an associative array
var surf_prices = new Array();
surf_prices["good"]=100;
surf_prices["pretty"]=200;
surf_prices["very"]=300;
surf_prices["epic"]=1000;
//Set up an associative array
//We use this this array when the user selects a size from the form
var size_prices= new Array();
size_prices["None"]=0;
size_prices["5 ft"]=100;
size_prices["6 ft"]=150;
size_prices["7 ft"]=200;
size_prices["8 ft"]=250;
size_prices["9 ft"]=300;
// getsurfboardPrice() finds the price based on the size of the Surfboard.
function getsurfboardPrice()
{
var surfboardPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the Surfboard the user Chooses name=selectedsurf":
var selectedsurf = theForm.elements["selectedsurf"];
//Here since there are 4 radio buttons selectedsurf.length = 4
//We loop through each radio buttons
for(var i = 0; i < selectedsurf.length; i++)
{
//if the radio button is checked
if(selectedsurf[i].checked)
{
//set surfboardPrice to value of elected radio button
// using the surf_prices array
//We get the selected Items value
surfboardPrice = surf_prices[selectedsurf[i].value];
//If we get a match then we break out of this loop
//No reason to continue if we get a match
break;
}
}
//return surfboardPrice
return surfboardPrice;
}
//This function finds the size price based on the
//drop down selection
function getSurfSize()
{
var surfSizePrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the select id="size"
var selectedsize = theForm.elements["size"];
//set Surfboardsize Price equal to value user chose
surfSizePrice = size_prices[selectedsize.value];
var clothPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeCloth"
var includeCloth = theForm.elements["includeCloth"];
//If they checked the box set cloth to 50
if(includeCloth.checked==true)
{
switch(surfSizePrice){
case size_prices["5 ft"]:
clothPrice = 50
break;
case size_prices["6 ft"]:
clothPrice = 100
break;
case size_prices["7 ft"]:
clothPrice = 150
break;
case size_prices["8 ft"]:
clothPrice = 200
break;
case size_prices["9 ft"]:
clothPrice = 250
break;
default:
clothPrice = 50
break;
}
}
//return clothPrice
return clothPrice;
surfSizePrice += clothPrice;
// return surfSizePrice
return surfSizePrice;
}
//footstrapPrices() finds foot strap price based on a check box selection
function footstrapPrices()
{
var footstrapPrice=0;
//Get a reference to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeFootStrap"
var includeFootStrap = theForm.elements["includeFootStrap"];
//If they checked the box set footstrapPrice to 5
if(includeFootStrap.checked==true)
{
footstrapPrice = 50;
}
//return footstrapPrice
return footstrapPrice;
}
function insciptionPrice()
{
//This local variable will be used to decide whether or not to charge for the inscription
//If the user checked the box this value will be 20
//otherwise it will remain at 0
var inscriptionPrice=0;
//Get a refernce to the form id="Surfboardform"
var theForm = document.forms["surfboardForm"];
//Get a reference to the checkbox id="includeinscription"
var includeInscription = theForm.elements["includeinscription"];
//If they checked the box set inscriptionPrice to 20
if(includeInscription.checked==true){
inscriptionPrice=20;
}
//return inscription price
return inscriptionPrice;
}
function calculateTotal()
{
//total price by calling functions
var SurfboardPrice = getsurfboardPrice() + getSurfSize() + footstrapPrices() + insciptionPrice();
//display result
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price For the Surfboard $"+SurfboardPrice;
}
function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
</script>
</head>
<body onload='hideTotal()'>
<div id="wrap">
<form action="" id="surfboardForm" onsubmit="return false;">
<div>
<div class="cont_order">
<fieldset>
<legend>Get a Surfboard!</legend>
<label >Type of Surfboard:</label><br />
<label class='radiolabel'><input type="radio" name="selectedsurf" value="good" onclick="calculateTotal()" />good surfboard ($100)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="pretty" onclick="calculateTotal()" />pretty good surfboard($200)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="very" onclick="calculateTotal()" />very good surfboard($300)</label><br/>
<label class='radiolabel'><input type="radio" name="selectedsurf" value="epic" onclick="calculateTotal()" />epic surfboard ($1000)</label><br/>
<br/>
<label>size</label>
<select id="size" name='size' onchange="calculateTotal()">
<option value="None">Select size</option>
<option value="5 ft">5 ft($100)</option>
<option value="6 ft">6 ft($150)</option>
<option value="7 ft">7 ft($200)</option>
<option value="8 ft">8 ft($250)</option>
<option value="9 ft">9 ft($300)</option>
</select>
<br/>
<p>
<label for='includeFootStrap' class="inlinelabel">Include epic Footstrap($50)</label>
<input type="checkbox" id="includeFootStrap" name='includeFootStrap' onclick="calculateTotal()" />
</p>
<br/>
<p>
<label for='includeCloth' class="inlinelabel">Include cool cloth($50)</label>
<input type="checkbox" id="includeCloth" name='includeCloth' onclick="calculateTotal()" />
</p>
<p>
<label class="inlinelabel" for='includeinscription'>Include Inscription($20)</label>
<input type="checkbox" id="includeinscription" name="includeinscription" onclick="calculateTotal()" />
<input type="text" id="theinscription" name="theinscription" value="Enter Inscription" />
</p>
<div id="totalPrice"></div>
</fieldset>
</div>
<input type='submit' id='submit' value='Submit' onclick="calculateTotal()" />
</div>
</form>
</div><!--End of wrap-->
</body>
</html>
williamsun
08-02-2012, 03:51 PM
Thank you again! You da man!
williamsun
08-03-2012, 12:01 AM
Just a quick question for later down the road.
If I wanted to subtract $25 from the total for a sale or something, would this be correct...
var SurfboardPrice = getsurfboardPrice() + getSurfSize() + footstrapPrices() + insciptionPrice() - 025.00;
bernie1227
08-03-2012, 01:01 AM
Personally, I'd set up a variable for later use in the long run, ie
var saleDiscount = 25;
var SurfboardPrice = getsurfboardPrice() + getSurfSize() + footstrapPrices() + insciptionPrice() - saleDiscount;
williamsun
08-03-2012, 01:15 AM
Ok, I'll do it that way. But would what I did work? (Just a self check)
Thanks
bernie1227
08-03-2012, 03:13 AM
Eh, maybe, the only problem as such, would be you should go - 25 rather than - 025.00
williamsun
08-03-2012, 03:24 AM
Ahh, ok. I was just trying to keep the same digit number for consistency with base prices being in the hundreds.
Thanks
bernie1227
08-03-2012, 03:58 AM
That makes sense, it isn't really a problem as much as a waste of space, any useless zeros are really interpreted the same as nothing, so:
025.00
Will be read the same as:
25
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.