Re: Proper coding? (JS newbie)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Dr J R Stockton" <jrs@xxxxxxxxxxxxxxxxxx> wrote in message
news:5zDMQ7QAkC4GFwG5@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
In microsoft.public.scripting.jscript message <46dfaa68$0$24580$ecde5a14
@news.coretel.net>, Thu, 6 Sep 2007 03:20:30, Paul E. Schoen
<pstech@xxxxxxxxx> posted:

My new version of this page will be posted at:

www.smart.net/~pstech/DogLicenseJS.htm

I'll be updating it as I learn more.

You should put the date visibly on the page, in standard form (i.e.
YYYY-MM-DD) so that anyone can see immediately how new it is.

OK. That is certainly a good idea. Done!


W3's free "HTML Tidy for Windows released on 19 April 2007" said :

line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 3 column 75 - Warning: discarding unexpected </meta>
line 131 column 12 - Warning: <input> attribute "+totalfee" lacks value
line 137 column 1 - Warning: replacing </p> by <br>
line 135 column 1 - Warning: missing </h3> before <p>
line 142 column 1 - Warning: replacing </p> by <br>
line 140 column 1 - Warning: missing </h3> before <p>
line 5 column 1 - Warning: <script> inserting "type" attribute
line 120 column 1 - Warning: <form> lacks "action" attribute
line 131 column 12 - Warning: <input> attribute "type" has invalid value
"number
"
line 136 column 1 - Warning: <input> attribute "type" has invalid value
"number"
line 134 column 1 - Warning: trimming empty <p>
line 139 column 1 - Warning: trimming empty <p>
Info: Document content looks like HTML 4.01 Transitional
Info: No system identifier in emitted doctype
13 warnings, 0 errors were found!

To learn more about HTML Tidy see http://tidy.sourceforge.net
Please send bug reports to html-tidy@xxxxxx
HTML and CSS specifications are available from http://www.w3.org/
Lobby your company to join W3C, see http://www.w3.org/Consortium

http://validator.w3.org/ said "Failed validation, 16 Errors"

I used the validator in Arachnophilia and it shows only three unmatched
tags, but they appear to matched. I've done extensive rewriting, so the
above no longer applies. I'll get a copy of HTML Tidy and try it.


Those are checking HTML, not script.

AdjustArray[0] = new Array(1.0, 1.1, 1.2, 1.5, 1.0);
can be
AdjustArray[0] = [1.0, 1.1, 1.2, 1.5, 1.0];
and the whole of AdjustArray can be given likewise.

Yes, that is more concise. I found I can use:
AdjustArray = [[1.0, 1.1, 1.2, 1.5, 1.0], [1.0, 1.1, 1.2, 1.5, 1.0], [1.0,
0.9, 0.8, 0.7, 1.0]];
But it might be better to assign the values separately to the three named
arrays.

parseInt(Form1.Weight.value) can probably be +Form1.Weight.value

Yes. That fixes the problem where 090 is not the same as 90. I found this
also in the FAQ.


Rather than using iter <= 4 you could read the actual length of the
array; one fewer thing to change if another button is added.

If one selects Multiple Bites then Minor Nip, it responds with Fee
increased by 110.000 001%. You mean 10%, not 110%; and I reduced the
offence so the fee should decrease. Re 100.000 001, see FAQ 4.6 and
links.

A 99-lb dog, minor nip, shows $54.67000000000001 - FAQ again.

I have fixed this using TotalFee.toFixed([2]). I also now use "adjusted
by", so that 110% is an increase and 80% is a decrease.


A 99-lb dog and an 099-lb dog cost differently.

This was caused by the parseInt function. It reads 099 as a zero, yet it
reads 010 as an 8. Apparently a leading zero indicates Octal. It's in the
FAQ.


Your new Array( 3, 5 ) is not a 2-dimensional array; Javascript does not
have them even though A[4,8] is meaningful.

It seems like the array can be accessed as a 3x5 array, as I have done with
AdjustArray[HumanBite][iter]. Is this the same as
AdjustArray[HumanBite,iter]?


I find the alerts tiresome; the text could easily be written to a
"latest change" readonly input control.

They were originally a debugging tool. I like to see what is being done for
each of those selections. Is there a way to have a message box with a
timeout so it just pops up for a second, and then closes?


Your hbh dbh obh are used as Booleans but given integer values;
javascript has Booleans.

I got confused when I used "True" rather than "true". Uppercase seems to be
inconsistent, because I can't use new array(1.0, 1.1, 1.2, 1.5, 1.0); it
must be capitalized.


AdjustArray is indexed only by literal numeric constants; names could be
used (*some* resemblance to an enumerated type).

I defined variable names to simulate enumeration. I could not find a way to
assign constants.


Sometimes I got lots of warnings in FireBug console that said:

Element referenced by ID/NAME in the global scope. Use W3C standard
document.getElementById() instead.

This was where I had used something like Form1.DogType.value. I could not
get the recommended function to work. Is this really a problem? I found a
reference to the standards at:

http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

Yes, the FAQ is very helpful. I've extensively changed the web page HTML
and script, and posted the new version. It looks better and works better. I
have tried to set it up with good structure and flow, which were the main
criticisms of my earliest efforts.

Now I need to dig into the details of CGI to have the information sent to
me when submitted.

Thanks,

Paul


.



Relevant Pages

  • Re: Plain text file on web server, questions please...
    ... I like to keep a single copy of this FAQ and then ... week and the FAQ is online all the time. ... it has no HTML tags in it to designate URL links and one ... a utility that would do this or can it be done with a shell script ...
    (alt.os.linux)
  • Re: COBOL FAQ *moved*
    ... I just accessed it with Firefox and had no problems with seeing it. ... FAQ for people who want a COBOL tutor (without being told to do their own ... using the tool that DW provides to 'Clean up WORD HTML'. ... I intend to keep ...
    (comp.lang.cobol)
  • Re: set/get in c++.
    ... >> of an array to the address of the first element except inside the ... I've contributed to the FAQ. ... > messages defending lame ideas on Usenet groups. ...
    (comp.lang.cpp)
  • Re: x86 binary runs; x86_64 binary throws segfault
    ... Frequently Asked Questions (FAQ) site, ... particularly the relationship between arrays and pointers. ... example, because I declared an array of char, then passed a pointer to ... I've already caught myself writing to ...
    (comp.lang.c)
  • Re: nested conditional that can identify parent page?
    ... and specify the files in the array including ... try to make as little php and html mix as possible, have a template ...
    (alt.php)