Re: Proper coding? (JS newbie)
- From: Randy Webb <HikksNotAtHome@xxxxxxx>
- Date: Tue, 04 Sep 2007 19:17:59 -0400
Paul E. Schoen said the following on 9/4/2007 1:22 PM:
I recently made a simple on-line form with some JScript to serve as a foundation on which to build a more extensive application. It is basically a questionnaire that calculates a dog license fee based on weight and other factors. I have extensive programming experience in many languages, including C, Delphi, and PIC and Z80 assembly, but I am fairly new to JScript.
Go to www.getfirefox.com, download it, and try your page in it. The javascript console will help with a lot of the things in your script that are either wrong, bad, or could be done better.
My code was severely criticized by someone, and I want to understand why that might be. Please comment on the code I have posted on my website at:
http://www.smart.net/~pstech/DogLicenseJS.htm
First, don't use MSWord to create HTML documents. MSWord is a Word Processor, not an HTML editor.
These are the first few lines of your script block with a few comments about just that part of it:
<SCRIPT LANGUAGE="JavaScript"> //!-- Beginning of JavaScript -
Comment:Ditch the language attribute and use type="text/javascript" instead.
// JSTest.js - 08/26/07 - Paul E. Schoen
var InitialFee = 20;
var TotalFee = 20;
function ComputeTotal () {
TotalFee = InitialFee + 0.3*parseInt(Form1.Weight.value);
Form1.Weight.value is depending on an IE-ism of making ID/NAME attributes global variables. Better is the forms collection and referencing it as:
document.forms['formName'].elements['elementName'].value;
You will also run across people who say that naming functions beginning with an uppercase letter is a bad habit. That is something I disagree with as it doesn't matter but it's a heads up that people may say something about it.
A lot of the check boxes would make the script simpler if you used select elements. Or, in the script, use a case/switch construct.
I just want to be be sure that I'm not really on the wrong path if I decide to expand on this simple script.
Start with the comp.lang.javascript FAQ.
http://jibbering.com/faq/index.html
It is a very good starting place to learn some things to do, and some things not to do. It also has references that might help you with the language.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
.
- Follow-Ups:
- Re: Proper coding? (JS newbie)
- From: Paul E. Schoen
- Re: Proper coding? (JS newbie)
- References:
- Proper coding? (JS newbie)
- From: Paul E. Schoen
- Proper coding? (JS newbie)
- Prev by Date: Proper coding? (JS newbie)
- Next by Date: Re: Proper coding? (JS newbie)
- Previous by thread: Proper coding? (JS newbie)
- Next by thread: Re: Proper coding? (JS newbie)
- Index(es):
Relevant Pages
|
Loading