Click to See Complete Forum and Search --> : Please Help Me
Falcon Niner
12-26-2002, 07:47 PM
I'm new to Javascript. Why isn't this code working? I just want it to do a simple calculation. I haven't taken any classes, and I don't understand books very well. I looked at other codes, and mine looks like it should work (that is how i learn, i have to know what i did wrong after doing, not just being thrown a bunch of code in a book) can anyone help me?
<head>
</style>
<SCRIPT LANGUAGE="JavaScript">
<!begin
function calc1(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=(a+b)*(4.35)
form.ans.value = c
}
// End -->
</script>
</head>
<body>
<form name="shields">
<table border=1 cellpadding=4 cellspacing=1>
<tr>
<td align=center>Calculate Shields Here
<br>
<br>
Current Land: <input type="text" name="a" size=5>
<br>
Future Land: <input type="text" name="b" size=5>
<br>
<br>
Answer: <input type="text" name="ans"
size=5>
<br>
<input type="button" value="Calculate" onClick="calc1(this.form)">
</tr>
</table>
</form>
</body>
AdamBrill
12-26-2002, 08:51 PM
Here's your error. On this line:
<!begin
change it to
<!--begin
That should make it work. However, there are a couple of things that you should change. First of all, put the whole code inside of <HTML> tags. Next, delete the </style> line up at the top. Those two things don't make it work, but they might mess up the code if you were trying to do something more complex. Let me know if it doesn't work...
jschweed3
12-26-2002, 08:55 PM
Yes, the tags that comment the codes out from older browsers:
<script language="javascript">
<!--
//-->
</script>
Take note: You don't need to write Hide Me and Stop Hiding, or Begin and End after the comment tags, but some writers do, while others don't.
A good book to learn Javascript:
Javascript Goodies
Joe Burns
Andree Growney
Very useful book, as it was the book I learned from :D
Falcon Niner
12-26-2002, 09:21 PM
Thanks a lot you guys! I will definitely check that book out. It works now, I can't believe I didn't see that when I was looking at other codes. Thanks again.:D :D :D
Falcon Niner
12-27-2002, 10:00 PM
I need help again (please?) what have I done wrong in this one?:
<h1>Are (You/They) Open?</h1>
<!--begin
function calc1(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=eval(form.c.value)
d=eval(form.d.value)
e=eval(form.e.value)
f=eval(form.f.value)
g=eval(form.g.value)
h=eval(form.h.value)
i=a+(4*b)+(5*c)+(9*d)+(4*e)
j=f+(9*g)+(4*h)
k=i-j
l=(k/i)*100
form.ans.value = l
}
// End -->
</script>
</head>
<body>
<form name="shields">
<table border=1 cellpadding=4 cellspacing=1>
<tr>
<td align=left>Calculate Shields Here
<br>
<br>
Soldiers Owned: <input type="text" name="a" size=5>
Soldiers Away: <input type="text" name="f" size=5>
<br>
Laser Troopers Owned: <input type="text" name="b" size=5>
<br>
Laser Dragoons Owned: <input type="text" name="c" size=5>
<br>
Tanks Owned: <input type="text" name="d" size=5>
Tanks Away: <input type="text" name="g" size=5>
<br>
Tac Fighters Owned: <input type="text" name="e" size=5>
Tac Fighters Away: <input type="text" name="h" size=5>
<br>
Percent Home: <input type="text" name="ans"
size=5> %
<br>
<input type="button" value="Calculate" onClick="calc1(this.form)">
<br>
If the answer is over 66%, then (You/They) are unopen.
<br>
If the answer is under 66%, then (You/They) are open.
</tr>
</table>
</form>
</body>
</html>
the error says that something was wrong with the variable "i"
Zach Elfers
12-27-2002, 10:38 PM
You haven't started the script with a:
<script language="JavaScript" type="text/JavaScript">
tag.
jschweed3
12-27-2002, 10:40 PM
I looked over that whole entire thing, and didn't see anything wrong...I can't believe I overlooked that...I should be shot :(
jeffmott
12-27-2002, 11:30 PM
Originally posted by Zach Elfers
<script language="JavaScript" type="text/JavaScript">
language has been deprecated in favor of type.
<script type="text/javascript">
Charles
12-28-2002, 05:50 AM
A good book to learn Javascript:
Javascript Goodies
Joe Burns
Andree GrowneyIf that book is anything like the the HTML Goodies web site then it will do more harm than good. Read instead JavaScript : The Definitive Guide by David Flanagan (http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=52DCNTYIVV&isbn=0596000480&itm=1)