JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 8th, 2012, 01:22 AM
langmp09 langmp09 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 langmp09 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 21 sec
Reputation Power: 0
Beginner - Help!

Hi all,
I am a beginner with javascript and programming: i have had a go at creating a piece of software with a form and 3 on click functions to process a quote: but it doesnt work!
Can anyone take a look and see if the logic is ok or whether i need to scrap it and start again?
The form works but will not call the test_click, clear_click or submit_click functions..
Underneath is the form
Cheers


<form action="" name="clientquoteform">

Business Name: <input type="text" name="businessname"><br>
Contact Name: <input type="text" name="contactname"><br>
Contact Number: <input type="text" name="contactnumber"><br>
Billing Address: <input type="text" name="billingaddress"><br>
Address Where Service is Required: <input type="text" name="serviceaddress"><br>
<br>



Choose From The Following: <br>
<input type="radio" name="regularoronce" value="regular">Regular Service
<input type="radio" name="regularoronce" value="once">Once-Only Service <br>
<br>



If Regular; How often do you require the service? <br>
<input type="radio" name="frequency" value="everymonth"> Every Month (12 per Year) <br>
<input type="radio" name="frequency" value="sixmonths"> Every Six Months (2 per Year) <br>
<input type="radio" name="frequency" value="annually"> Annually (1 per Year) <br>
<br>

If Regular; What is the length of the contract? <br>
<input type="radio" name="contractlength" value="oneyear"> 1 Year <br>
<input type="radio" name="contractlength" value="twoyears"> 2 Years <br>
<input type="radio" name="contractlength" value="threeyears"> 3 Years <br>
<br>




How many people are to be served?
<input type="text" name="numberpeople"><br>
<br>


Is the buffet meal: <br>
<input type="radio" name="numbercourses" value="onecourse"> 1 Course <br>
<input type="radio" name="numbercourses" value="twocourses"> 2 Courses <br>
<br>


Is the buffet meal to include tea or coffee? <br>
<input type="radio" name="teacoffee" value="yes"> Yes <br>
<input type="radio" name="teacoffee" value="no"> No <br>
<br>


Is the service to be prepared: <br>
<input type="radio" name="onsiteoffsite" value="onsite"> On-Site <br>
<input type="radio" name="onsiteoffsite" value="offsite"> Off-Site and Delivered <br>
<br>


<br>
<input type="button" value="Check Details" onclick="test_click();">
<br>

<input type="reset" value="Reset" onclick="clear_click();">


<input type="submit" value="Submit" onclick="submit_click();">
<br>
<br>
<textarea name="output" rows="15" cols="40">
</textarea>

Reply With Quote
  #2  
Old October 8th, 2012, 01:47 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,932 Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level)Winters User rank is General 25th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 12 h 55 m 12 sec
Reputation Power: 2632
Welcome to DevShed, langmp.

Can you post everything please, including the Javascript.
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
  #3  
Old October 8th, 2012, 02:36 AM
langmp09 langmp09 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 langmp09 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 21 sec
Reputation Power: 0
<head>
<h1> BuffetQuote Application </h1>
</head>

<body>
<script language = "javascript">


//declaring variables

var myForm = document.form1;

var businessName = myForm.businessname.value;
var contactName = myForm.contactname.value;
var contactNumber = myForm.contactnumber.value;
var billingAddress = myForm.billingaddress.value;
var serviceAddress = myForm.serviceaddress.value;

var regular = myForm.regularoronce.regular;
var once = myForm.regularoronce.once;

var everyMonth = myForm.frequency.everymonth;
var sixMonths = myForm.frequency.sixmonths;
var annually = myForm.frequency.annually;

var oneYear = myForm.contractlength.oneyear;
var twoYears = myForm.contractlength.twoyears;
var threeYears = myForm.contractlength.threeyears;

var numberPeople = myForm.numberpeople.value;

var oneCourse = myForm.numbercourses.onecourse;
var twoCourses = myForm.numbercourses.twocourses;

var teaCoffee = myForm.teacoffee.yes;
var noTeaCoffee = myForm.teacoffee.no;

var onSite = myForm.onsiteoffsite.onsite;
var offSite = myForm.onsiteoffsite.offsite;

var output = myForm.output.value

var totalCost;
var Gst;
var totalCostGst;



//function 1: onclick from 'check details' button. validates form entries.

function test_click()
{

//validate that number of people is a number

if(isNaN(numberPeople) == true)
{
alert("Please enter a valid number");
}

//validate that regular or once radio is completed

if (regular== null && once == null)
{
alert("Please complete all sections");
return;
}

//validate that frequency radio is completed

if (everyMonth==null && sixMonths==null && annually==null)
{
alert("Please complete all sections");
return;
}

//validate that contract length radio is completed

if (oneYear==null && twoYears==null && threeYears==null)
{
alert("Please complete all sections");
return;
}

//validate that number of courses radio is completed

if (oneCourse== null && twoCourses == null)
{
alert("Please complete all sections");
return;
}

//validate that tea or coffee radio is completed

if (teaCoffee== null && noTeaCoffee == null)
{
alert("Please complete all sections");
return;
}

//validate that onsite or offsite radio is completed

if (onSite== null && offSite== null)
{
alert("Please complete all sections");
return;
}

//validate that all entry boxes are completed

if (businessName==""||contactName==""||billingAddress==""||serviceAddress==""||contactNumber==""||numberPeople=="")
{
alert("Please complete all sections");

}

//validate that the form is successfully completed, requests user to submit

else
{
alert("Details are valid: Please click submit");

}


}


//function 2: reset: clears form and starts from blank

function clear_click()
{
document.getElementById("clientquoteform").reset();
alert("Form Reset")
}


//function 3: submit: calculates the quote and outputs the variables

function submit_click()
{

//calculate base cost for less than 30people, 1 course

if (numberPeople <= 30 && oneCourse)
{
totalCost = 10 * numberPeople;
}

//calculate base cost for less than 30 people, 2 courses

if (numberPeople <= 30 && twoCourses)
{
totalCost = 15 * numberPeople;
}

//calculate base cost for over 30 people, 1 course

if (numberPeople > 30 && oneCourse)
{
totalCost = 8 * numberPeople;
}

//calculate base cost for between 30 and 60 people, 2 courses

if (numberPeople > 30 && numberPeople <=60 && twoCourses)
{
totalCost = 12 * numberPeople;
}

//calculate base cost for over 60 people, 2 courses

if (numberPeople > 60 && twoCourses)
{
totalCost = 11 * numberPeople;
}

//calculate additional cost of tea or coffee, and add text to variable for output

if (teaCoffee)
{
totalCost = totalCost + (2 * numberPeople);
teaCoffee = "Tea or Coffee Included";
}

//calculate additional cost of delivery, and add text to variable for output

if(offSite)
{
totalCost = totalCost + (totalCost * 0.03);
offSite = "Prepared Off-Site - Delivery Included";
}

//calculate discount of every month service, and add text to variable for output

if(everyMonth)
{
totalCost = totalCost - (totalCost * 0.05);
everyMonth = "Monthly Service Selected";
{

//calculate the discount of six monthly service, and add text to variable for output

if(sixMonths)
{
totalCost = totalCost - (totalCost * 0.04);
sixmonths = "Six Monthly Service Selected";
}

//calculate the discount of annual service, and add text to variable for output

if(annually)
{
totalCost = totalCost - (totalCost * 0.03);
annually = "Annual Service Selected";
}

//calculate the discount of a one year contract, and add text to variable for output

if(oneYear)
{
totalCost = totalCost - (totalCost * 0.02);
oneYear = "One Year Contract Selected";
}

//calculate the discount of a two year contract, and add text to variable for output

if(twoYears)
{
totalCost = totalCost - (totalCost * 0.04);
twoYears = "Two Year Contract Selected";
}

//calculate the discount of a three year contract, and add text to variable for output

if(threeYears)
{
totalCost = totalCost - (totalCost * 0.06);
threeYears = "Three Year Contract Selected";

}


//add text to other possible radio variables for output

if(regular)
{
regular = "Regular Service Selected";
}
if(once)
{
once = "Once-Only Service Selected";
}
if(oneCourse)
{
oneCourse = "One-Course Meal Selected";
}
if(twoCourses)
{
twoCourses = "Two-Course Meal Selected";
}
if(noTeaCoffee)
{
noTeaCoffee = "No Tea or Coffee Selected";
}

//convert total cost to 2 decimal places

totalCost = totalCost.toFixed(2);
totalCost = "Pre-GST Total Cost = $" + totalCost;


//calculate GST to 2 decimal places

Gst = totalCost * 0.1
Gst = Gst.toFixed(2)
Gst = "GST Added = $" + Gst;

//calculate total cost with GST included

totalCostGst = totalCost + Gst
totalCostGst = "Total Cost including GST = $" + totalCostGst;

//output all required variables in text field

output = (businessName + "<br>" + contactName + "<br>" + contactNumber +
"<br>" + billingAddress + "<br>" + serviceAddress + "<br>" + regular +
"<br>" + once + "<br>" + everyMonth + "<br>" + sixMonths + "<br>" + annually +
"<br>" + oneYear + "<br>" + twoYears + "<br>" + threeYears + "<br>" + numberPeople +
"<br>" + oneCourse + "<br>" + twoCourses + "<br>" + teaCoffee + "<br>" + noTeaCoffee +
"<br>" + onSite + "<br>" + offSite + "<br>" + totalCost + "<br>" + Gst + "<br>" + totalCostGst )

}

</script>


<form name="clientquoteform" action ="">

Business Name: <input type="text" name="businessname"><br>
Contact Name: <input type="text" name="contactname"><br>
Contact Number: <input type="text" name="contactnumber"><br>
Billing Address: <input type="text" name="billingaddress"><br>
Address Where Service is Required: <input type="text" name="serviceaddress"><br>
<br>

Choose From The Following: <br>
<input type="radio" name="regularoronce" value="regular">Regular Service
<input type="radio" name="regularoronce" value="once">Once-Only Service <br>
<br>

If Regular; How often do you require the service? <br>
<input type="radio" name="frequency" value="everymonth"> Every Month (12 per Year) <br>
<input type="radio" name="frequency" value="sixmonths"> Every Six Months (2 per Year) <br>
<input type="radio" name="frequency" value="annually"> Annually (1 per Year) <br>
<br>

If Regular; What is the length of the contract? <br>
<input type="radio" name="contractlength" value="oneyear"> 1 Year <br>
<input type="radio" name="contractlength" value="twoyears"> 2 Years <br>
<input type="radio" name="contractlength" value="threeyears"> 3 Years <br>
<br>

How many people are to be served?
<input type="text" name="numberpeople"><br>
<br>

Is the buffet meal: <br>
<input type="radio" name="numbercourses" value="onecourse"> 1 Course <br>
<input type="radio" name="numbercourses" value="twocourses"> 2 Courses <br>
<br>

Is the buffet meal to include tea or coffee? <br>
<input type="radio" name="teacoffee" value="yes"> Yes <br>
<input type="radio" name="teacoffee" value="no"> No <br>
<br>

Is the service to be prepared: <br>
<input type="radio" name="onsiteoffsite" value="onsite"> On-Site <br>
<input type="radio" name="onsiteoffsite" value="offsite"> Off-Site and Delivered <br>
<br>

<br>
<input type="button" value="Check Details" onclick="test_click()">
<br>

<input type="reset" value="Reset" onclick="clear_click()">

<input type="submit" onclick="submit_click()" value="Submit"">
<br>
<br>
<textarea name="output" rows="15" cols="40">
</textarea>

</form1>

</body>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Beginner - Help!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap