Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

really stuck - new to javascript

Status
Not open for further replies.

gazhayes

Technical User
Apr 15, 2008
1
Hi all,

I don't want to be lazy and ask someone to just try to find out whats wrong with my code, but I've been working on this for about an hour and cant make it work. I dont have any js books and anyway I'm more of a learn by doing kind of guy, actually today is the first time i used js and I have adapted this script to what I want but argh....

If anyone can give me some pointers that would be great! thanks :)

Here is the code that isn't working:
Code:
function processForm() {
//get form variables
//var theItems = document.getElementsByName( "item" );
var thePgs = Number( document.getElementById( "pgs" ).value );
var theChr = Number( document.getElementById( "chr" ).value );
var theFld = document.getElementsByName( "fld" );
var theTbl = Number( document.getElementById( "tbl" ).value );
var theTme = document.getElementsByName( "tme" );
var theFrm = document.getElementsByName( "frm" );
var theCur = document.getElementsByName( "cur" );
//var theTbl = document.getElementById( "tbl").checked;


//variable for selected item
var selectedFld;
var selectedTme;
var selectedFrm;
var selectedCur;

//variable for order total
var orderTotal = 0.00;

//the display box
var outBox = document.getElementById( "total" );



//select boxes 
for(var i = 0; i < theFld.length; i++) {
if( theFld[i].checked) {
selectedFld = theFld[i].value;
break;
}
for(var i = 0; i < theTme.length; i++) {
if( theTme[i].checked) {
selectedTme = theTme[i].value;
break;
}
for(var i = 0; i < theFrm.length; i++) {
if( theFrm[i].checked) {
selectedFrm = theFrm[i].value;
break;
}
for(var i = 0; i < theCur.length; i++) {
if( theCur[i].checked) {
selectedCur = theCur[i].value;
break;
}
}
//Field 
switch(selectedFld) {
case "A":
total = 1.0;
break;B
case "":
total = 1.1;
break;
case "C":
total = 1.2;
break;
default:
total = 0.00;
}

//Time 
switch(selectedTme) {
case "A":
total = 1.0;
break;B
case "":
total = 1.1;
break;
case "C":
total = 1.2;
break;
default:
total = 0.00;
}

//Format 
switch(selectedFrm) {
case "A":
total = 1.0;
break;B
case "":
total = 1.1;
break;
case "C":
total = 1.2;
break;
default:
total = 0.00;
}

//Currency 
switch(selectedCur) {
case "A":
total = 1.0;
break;B
case "":
total = 1.1;
break;
case "C":
total = 1.2;
break;
default:
total = 0.00;
}


//figure final total
total = (((thePgs * theChr * theFld) + theTbl) * theTme * theFrm) * theCur;

//output to text box
outBox.value = "$" + total.toString();

And here is the html im using:

Code:
<form id="form1" action="" method="get">
Number of pages<input type="text" id="pgs" size="3" maxlength="3" value="1" />
Characters per page<input type="text" id="chr" size="3" maxlength="3" value="1" />
<input type="radio" name="fld" value="A" />Mining

<input type="radio" name="fld" value="B" />Geology

<input type="radio" name="fld" value="C" />Finance


<input type="radio" name="tme" value="A" />24 Hours

<input type="radio" name="tme" value="B" />3 Days

<input type="radio" name="tme" value="C" />1 Week


<input type="radio" name="frm" value="A" />Word Document

<input type="radio" name="frm" value="B" />PDF

<input type="radio" name="frm" value="C" />Image or Fax



<input type="radio" name="cur" value="A" />AUD

<input type="radio" name="cur" value="B" />RMB

<input type="radio" name="cur" value="C" />HKD

How many tables or diagrams?<input type="text" id="tbl" size="3" maxlength="3" value="1" />

Your total: <input type="text" id="total" size="10" maxlength="10" readonly="readonly" value="0" />

<input type="button" id="submit" value="Calculate Estimate cost" onclick="processForm()" />

</form>
 
If you want help, then help us to help you. A good start would be by telling us :

- What is the code not doing that it should be?

- What is the code doing that it should not be?

- What errors do you see (if any)?

- What browser(s) is the code not working in?

- What the code is actually meant to do

Given we have no idea of any of this, it'd be pretty hard to help you.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Everywhere where this block appears:
>case "A":
>total = 1.0;
>break;[highlight]B[/highlight]

Why is the "B" there???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top