Arrtu
01-10-2004, 06:38 PM
I am currently teaching myself javascript from a variety of sources, and I think I have got to grips with variables. What I am now trying to get on top of is variables and the math function. That is, using a form, I type in a number or character. I then type in a percentage into a second box and hit my go button. It returns a value defined in a variable which relates to the number I typed and calculates its percentage based on the second number I typed. So far so good. On running the script I return an error, which I assume is either my math or how I am trying to pass the value into my form:
<SCRIPT LANGUAGE="javascript">
function decide(){
var choice=document.form1.number.value;
if (choice<1)
document.form1.hundreds.value = 000;
if (choice==1)
document.form1.hundreds.value = 100;
if (choice==2)
document.form1.hundreds.value = 200;
if (choice==3)
document.form1.hundreds.value = 300;
var second=document.form1.percentage.value;
var show=math.round(hundreds / 100) * second;
document.form1.displaynumber.value=show
}
</SCRIPT>
<form name="form1">
number:<input type="text" size=10 name="number"><BR>
% multiple:<input type="text" size=10 name="percentage">
<INPUT TYPE="button" value="go" onClick="decide();"><P>
value:<input type="text" size=10 name="hundreds" readonly><BR>
percentage value:<input type="text" size=10 name="displaynumber" readonly>
</FORM>
As I said, I am teaching myself and I have tried various methods of resolving the issue, as I feel this is the best way to learn; but I now think it is time to ask an expert.
can anyone tell me where I have gone wrong, as I am going blind staring at my javascript bible? thanx in advance.
<SCRIPT LANGUAGE="javascript">
function decide(){
var choice=document.form1.number.value;
if (choice<1)
document.form1.hundreds.value = 000;
if (choice==1)
document.form1.hundreds.value = 100;
if (choice==2)
document.form1.hundreds.value = 200;
if (choice==3)
document.form1.hundreds.value = 300;
var second=document.form1.percentage.value;
var show=math.round(hundreds / 100) * second;
document.form1.displaynumber.value=show
}
</SCRIPT>
<form name="form1">
number:<input type="text" size=10 name="number"><BR>
% multiple:<input type="text" size=10 name="percentage">
<INPUT TYPE="button" value="go" onClick="decide();"><P>
value:<input type="text" size=10 name="hundreds" readonly><BR>
percentage value:<input type="text" size=10 name="displaynumber" readonly>
</FORM>
As I said, I am teaching myself and I have tried various methods of resolving the issue, as I feel this is the best way to learn; but I now think it is time to ask an expert.
can anyone tell me where I have gone wrong, as I am going blind staring at my javascript bible? thanx in advance.