My friend and I are trying to start a business and are writing a website of our own. We have been trying to create an online estimator and are having trouble with writing the javascript that is to handle the form data. I am having trouble capturing the form data for use using the onsubmit operator. We have written all of the options using list boxes using numbers as the values. I have attempted to create a user defined function to caculate the total and I have tried to use an alert box to give the instant result to the user before submitting the info to us. However, I am not sure that I am using the correct syntax to capture the value of the list boxes. Also, I am not sure that my user defined function is written properly. In fact, I can't even get my function to return an alert box even after inserting a if-else statement with alert boxes as both actions. I have to admit that I am new to Javascript (I learned it this weekend) and this is my 1st real project. I could really use some help here. Also, where can I find out how to write the server-side javascript needed for processing data after the submission. Below I have included a smaller version of the code that I wrote. PLEASE HELP!!!
[code=html]
<html>
<head>
<title>Online Estimator</title>
<!--[/code][code=javascript]
<script language="Javas cript" type="text\java script">
function formTotal () {
var ourForm = document.forms[0];
var aquariumIdx = ourForm.aquariu m.selectedIndex ;
var aquarium = ourForm.aquariu m.options[aquariumIdx].value;
var tableIdx = ourForm.table.s electedIndex;
var table = ourForm.table.o ptions[tableIdx].value;
var bedIdx = ourForm.bed.sel ectedIndex;
var bed = ourForm.bed.opt ions[bedIdx].value;
var couchIdx = ourForm.couch.s electedIndex;
var couch = ourForm.couch.o ptions[couchIdx].value;
var chairsIdx = ourForm.chairs. selectedIndex;
var chairs = ourForm.chairs. options[chairsIdx].value;
var milesIdx = ourForm.miles.s electedIndex;
var miles = ourForm.miles.o ptions[milesIdx].value;
var longWalkIdx = ourForm.longWal k.selectedIndex ;
var longWalk = ourForm.longWal k.options[longWalkIdx].value;
var stairflightsIdx = ourForm.stairfl ights.selectedI ndex;
var stairflights = ourForm.stairfl ights.options[stairflightsIdx].value;
var preTotal = aquarium + table + bed + couch + chairs + miles;
var preTotal2 = preTotal * longWalk;
var Total = preTotal2 * stairflights;
return = alert (Total)
}
</script>[/code][code=html]
-->
</head>
<body>
<h1><b>Online Esitmator</b></h1>
<form action = "#" onsubmit = "return formTotal()">
<b>Aquariums: </b>
<select name = "aquarium">
<option value = "0">0</option>
<option value = "3">1</option>
<option value = "6">2</option>
<option value = "9">3</option>
</select>
<b>Tables:</b>
<select name = "table">
<option value = "0">0</option>
<option value = "6">1</option>
<option value = "12">2</option>
<option value = "18">3</option>
<option value = "24">4</option>
</select>
<b>Beds:</b>
<select name = "bed">
<option value = "0">0</option>
<option value = "10">1</option>
<option value = "20">2</option>
<option value = "30">3</option>
<option value = "40">4</option>
</select>
<b>Couches:</b>
<select name = "couch">
<option value = "0">0</option>
<option value = "10">1</option>
<option value = "20">2</option>
<option value = "30">3</option>
<option value = "40">4</option>
</select>
<b>Chairs:</b>
<select name = "chairs">
<option value = "0">0</option>
<option value = "3">1</option>
<option value = "6">2</option>
<option value = "9">3</option>
<option value = "12">4</option>
<option value = "15">5</option>
</select>
<b>Miles between Locations:</b>
<select name = "miles">
<option value = "5">Under 10</option>
<option value = "10">10-20</option>
<option value = "15">20-30</option>
<option value = "20">30-40</option>
</select>
<b>Long Walk:</b>
<select name = "longWalk">
<option value = "1">No</option>
<option value = "1.2">From Only</option>
<option value = "1.2">To Only</option>
<option value = "1.4">To and From</option>
</select>
<b>Flights of Stairs:</b>
<select name = "stairfligh ts">
<option value = "1">None</option>
<option value = "1.2">1 flight</option>
<option value = "1.4">2 flights</option>
<option value = "1.6">3 flights</option>
<option value = "1.8">4 flights</option>
<option value = "2.0">5 flights</option>
<option value = "2.2">6 flights</option>
</select>
<input type = "submit" value = "Get Estimate!">
</form>
</body>
</html>
[/code]
If anyone can give some insight, it would be greatly appreciated...
-JOE-
[code=html]
<html>
<head>
<title>Online Estimator</title>
<!--[/code][code=javascript]
<script language="Javas cript" type="text\java script">
function formTotal () {
var ourForm = document.forms[0];
var aquariumIdx = ourForm.aquariu m.selectedIndex ;
var aquarium = ourForm.aquariu m.options[aquariumIdx].value;
var tableIdx = ourForm.table.s electedIndex;
var table = ourForm.table.o ptions[tableIdx].value;
var bedIdx = ourForm.bed.sel ectedIndex;
var bed = ourForm.bed.opt ions[bedIdx].value;
var couchIdx = ourForm.couch.s electedIndex;
var couch = ourForm.couch.o ptions[couchIdx].value;
var chairsIdx = ourForm.chairs. selectedIndex;
var chairs = ourForm.chairs. options[chairsIdx].value;
var milesIdx = ourForm.miles.s electedIndex;
var miles = ourForm.miles.o ptions[milesIdx].value;
var longWalkIdx = ourForm.longWal k.selectedIndex ;
var longWalk = ourForm.longWal k.options[longWalkIdx].value;
var stairflightsIdx = ourForm.stairfl ights.selectedI ndex;
var stairflights = ourForm.stairfl ights.options[stairflightsIdx].value;
var preTotal = aquarium + table + bed + couch + chairs + miles;
var preTotal2 = preTotal * longWalk;
var Total = preTotal2 * stairflights;
return = alert (Total)
}
</script>[/code][code=html]
-->
</head>
<body>
<h1><b>Online Esitmator</b></h1>
<form action = "#" onsubmit = "return formTotal()">
<b>Aquariums: </b>
<select name = "aquarium">
<option value = "0">0</option>
<option value = "3">1</option>
<option value = "6">2</option>
<option value = "9">3</option>
</select>
<b>Tables:</b>
<select name = "table">
<option value = "0">0</option>
<option value = "6">1</option>
<option value = "12">2</option>
<option value = "18">3</option>
<option value = "24">4</option>
</select>
<b>Beds:</b>
<select name = "bed">
<option value = "0">0</option>
<option value = "10">1</option>
<option value = "20">2</option>
<option value = "30">3</option>
<option value = "40">4</option>
</select>
<b>Couches:</b>
<select name = "couch">
<option value = "0">0</option>
<option value = "10">1</option>
<option value = "20">2</option>
<option value = "30">3</option>
<option value = "40">4</option>
</select>
<b>Chairs:</b>
<select name = "chairs">
<option value = "0">0</option>
<option value = "3">1</option>
<option value = "6">2</option>
<option value = "9">3</option>
<option value = "12">4</option>
<option value = "15">5</option>
</select>
<b>Miles between Locations:</b>
<select name = "miles">
<option value = "5">Under 10</option>
<option value = "10">10-20</option>
<option value = "15">20-30</option>
<option value = "20">30-40</option>
</select>
<b>Long Walk:</b>
<select name = "longWalk">
<option value = "1">No</option>
<option value = "1.2">From Only</option>
<option value = "1.2">To Only</option>
<option value = "1.4">To and From</option>
</select>
<b>Flights of Stairs:</b>
<select name = "stairfligh ts">
<option value = "1">None</option>
<option value = "1.2">1 flight</option>
<option value = "1.4">2 flights</option>
<option value = "1.6">3 flights</option>
<option value = "1.8">4 flights</option>
<option value = "2.0">5 flights</option>
<option value = "2.2">6 flights</option>
</select>
<input type = "submit" value = "Get Estimate!">
</form>
</body>
</html>
[/code]
If anyone can give some insight, it would be greatly appreciated...
-JOE-
Comment