![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jan 2008
Location: Hawaii
Posts: 81
OS: Vista, Ubuntu
|
Help with a very basic javascript/html web calculator program?
I don't get why it doesn't work. Here's the code:
<HTML> <HEAD> <TITLE> Lab no. 3 Cole Stevens </TITLE> <script language="Javascript"> function calculate(form) { var answer = eval(form.valueA.value); form.valueB.value= answer; } function clearbox(form) { form.valueA.value=""; form.valueB.value=""; } </SCRIPT> <BODY> <FORM NAME="math"> <P> Mathematical expression: <INPUT TYPE="text" NAME="valueA" SIZE="20"> <P> Answer: <INPUT TYPE="text" NAME="valueB" SIZE="20"> <P> <INPUT TYPE="button" VALUE="Calculate!" NAME="calculate" onClick="calculate(this.form)"> <P> <INPUT TYPE="button" VALUE="Clear" NAME="clear" onClick="clearbox(this.form)"> </BODY> Any and all help is greatly appreciated. Thanks! |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,864
OS: Vista, various linux distros
|
Re: Help with a very basic javascript/html web calculator program?
Hey it took me a few to work out what the problem was. But basically you're using the same names all over the place, so when you call "calculate(this.form)" the browser thinks you're referring to the form object (which is the button that calls calculate).
Fix(note the bold): Code:
<INPUT TYPE="button" VALUE="Calculate" NAME="calc" onClick="calculate(this.form)"> Cheers, Jamey |
|
|
|
![]() |
| Thread Tools | |
|
|