View Single Post
Old 09-24-2012, 08:25 AM   PM User | #3
Liz.2012
New to the CF scene

 
Join Date: Sep 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Liz.2012 is an unknown quantity at this point
Hi Philip,
Thanks for your response. I've studied the code overnight and see I had completely gone wrong. I was confused with if/else/then/do/while.

I'm still unsure how to do the calculations at the end. Can you give me an example? Is it something like this..

var totppl = document.form1.numPeople.value
var coursechoice = document.form1.course.value
var tot = numPeople*15
var = if (numPeople <=30 && numPeople ==1)
{document.write (tot);
}
else if (numPeople <=30 &&numPeople==1)
{document.write (tot);
}





var totalcost = numberofpeople*30", or something similar, instead of "var totalcost = prompt(numberofpeople*30)"?

<form name = "form1" action = "">

<h3>Number of people (1-60): <input type="text" name="numPeople" size ="2" maxlength = "2"></h1>

<h3>Select number of courses required</h3>
<input type="radio" name="course" value="1" /> One Course
<input type="radio" name="course" value="2" /> Two Course
<br /><br />

<input type="button" value="Submit Quote" onclick="checkForm()"/>
<input type="reset" value="Reset Quote"/>

<h3>Total Cost: <input type="text" name="tlcost" size="6" readonly;</h3>

</form>


<script type="text/javascript">

function checkForm() {
var people = Number(document.form1.numPeople.value) || 0; // 0 if NaN entered
if ((people <= 0) || (people >60)) {
alert ("You must enter a number from 1 to 60");
document.form1.numPeople.value = ""; // clear the field
return false; // go no further
}

var c= 0;
var f = document.form1.course; // avoid repetition
for (var i =0; i < f.length; i++) { // loop through the radio buttons to determine which one checked
if (f.course[i].checked) {
c = f.course[i].value; // 1 or 2, not "one or "two" as you want to use this value in a subsequent calculation
}
}
if (c ==0) { // no radio selected
alert ("You must select one or two courses");
return false;
}

var tot = 0;
Liz.2012 is offline   Reply With Quote