0

I'm try to create a simple form that spits out a measurement. For Example 32 B should be (32+5)=37

I'm not sure whats wrong. Please help~ Thanks so much!

<HTML>
<HEAD>
<TITLE>Bra Size to Chest Size</TITLE>

<SCRIPT LANGUAGE="JavaScript">

function CalculateSum(Atext, Btext, form)
{
var A = parseFloat(Atext);
var B = parseFloat(this.CuptoNum(Btext));
form.Answer.value = A + B;
}

/* ClearForm: this function has 1 argument: form.
   It clears the input and answer fields on the form.
   It needs to know the names of the INPUT elements in order
   to do this. */

function ClearForm(form)
{
form.input_A.value = "";
form.input_B.value = "";
form.Answer.value = "";
}

function CuptoNum(str)
{
if((str >= 0) && (str <= 9))
return str;
switch(str.toUpperCase()) {
case "A": return 4;
case "B": return 5;
case "C": return 6;
case "D": return 7;
case "E": return 8;
case "F": return 9;
default:  alert('You must choose a number between 0 and 9 or a letter between A and F!');
return 'X';
}


// end of JavaScript functions -->
</SCRIPT>
</HEAD>

<BODY>

<P><FONT SIZE="+2">Simple Adder</FONT></P>

<FORM NAME="Calculator" METHOD="post">
<P>Enter a number: <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P>
<P>Enter a number: <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P>
<P><INPUT TYPE="button" VALUE="Add Numbers" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form)"></P>
<P><INPUT TYPE="button" VALUE="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></P>
<P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
</FORM>

</BODY>
</HTML>
1
  • you should definitely specify what error message you are receiving when asking a question like this one. Commented Mar 2, 2010 at 8:54

2 Answers 2

1

change this.CuptoNum(Btext) to CuptoNum(Btext);

there is no need to use 'this' object. you are not refering to any class here.

Sign up to request clarification or add additional context in comments.

Comments

0

Your CuptoNum function starts off with a check if str is between 0 and 9, while clearly, it will not be a number at all. You want to change that to something like

if("ABCDEF".indexOf(str.toUpperCase() == -1))
    return str;

or remove that check altogether, as you have a default clause in your switch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.