Re: Proper coding? (JS newbie)
- From: "Paul E. Schoen" <pstech@xxxxxxxxx>
- Date: Wed, 5 Sep 2007 00:16:43 -0400
"Randy Webb" <HikksNotAtHome@xxxxxxx> wrote in message
news:WbidnSa9h9mCekDbRVn_vw@xxxxxxxxxxxxxxx
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.
I've been just running it on IE, but the error messages are not helpful.
Hopefully Firefox will show the errors more clearly.
Yes, I started the web page using MS Word, and then found that it actually
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.
removed the script when viewing the source. I am now using Arachnophilia,
but it does not have a good way to see the results.
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;
That should be very helpful, especially if I want to reference the elements
as an array, which was suggested.
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.
I'm used to Delphi, which is not case sensitive, but variable names and
functions usually start with an uppercase. Sometimes a lowercase letter is
prepended indicating variable type (like nCount for integer or sName for
string). I find it difficult not to predefine all the variable types, and
I've been stung a few times in JScript, where case matters.
A lot of the check boxes would make the script simpler if you used selectIn my book, "Using JScript" (c1997), it shows the case/switch as a Java
elements. Or, in the script, use a case/switch construct.
Language construct, along with other distinctions from JScript. I probably
need a newer book!
Many thanks for your helpful comments. I'm not doing any serious projectsI 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.
right now, but I want to get some experience and instruction in the proper
way to use the language.
Paul
.
- Follow-Ups:
- Re: Proper coding? (JS newbie)
- From: \(O\)enone
- Re: Proper coding? (JS newbie)
- References:
- Proper coding? (JS newbie)
- From: Paul E. Schoen
- Re: Proper coding? (JS newbie)
- From: Randy Webb
- Proper coding? (JS newbie)
- Prev by Date: Re: Proper coding? (JS newbie)
- Next by Date: Calling ActiveX component method from JScript
- Previous by thread: Re: Proper coding? (JS newbie)
- Next by thread: Re: Proper coding? (JS newbie)
- Index(es):
Relevant Pages
|