logo To Foot
© J R Stockton, ≥ 2010-02-08

JavaScript Miscellany 1.

No-Frame * Framed Index * Frame This
Links within this site :-

See "About This JavaScript Site" in JavaScript Index and Introduction.

ISSN & ISBN Validation

ISBN-13 has been introduced to supersede ISBN-10; no new ISBN-10 should be issued after 2006. For a description of ISBN-13, see at isbn-international; thanks to Paul Harper of NM Library for finding that document.

The final character of each Number is a check digit, calculated from the seven, nine or twelve descriptive digits of the Main Part. ISSN and ISBN-10 use corresponding digit-weighting algorithms; that for ISBN-13 differs.

ISBN-10 converts to ISBN-13 by prepending an EAN UCC (generally 978) and recalculating the check digit.

For each form, there are functions below to verify a full ISSN or ISBN and to calculate the check digit (as a one-character string) from the main part. Input to those is free-format, but for ISNCodeTest the check digit must be the final character.

In the following code, 9999 is merely a sufficiently large multiple of 11.

ISSN-8

Written on the assumption that ISSN-8 is like ISBN-10, which fits test ISSNs.

ISSN-8
   
   

ISBN-10

ISBN-10
   
   

Some ISBN-10 Formats

ISBN-13

ISBN-13
   
   

For showing the EAN bar code corresponding to an ISBN-13 number, see Bar Code.

Bar Code

Bar codes can be drawn by positioning black and white divisions.

Beware the effects of various forms of Zoom in various browsers.

UPC & EAN (for GTIN)

This at least approaches accordance with Wikipedia Universal Product Code (UPC) and European Article Number (EAN-13), including ISBN-13. For validating ISBN numbers, see also ISBN-13.

The bar code structure is created either by composing an HTML string or by using DOM methods. It could also be done by using a table for the layout and using DOM methods to add the values.

Any actual user must test and adjust the code for complete conformity with the actual standards.

In UPC, a leading zero is (often?) printed but not encoded. In EAN, it is encoded by bar-parity. Non-digits are ignored. Samples :-
  • UPC : 0 000168 461651;
  • EAN : 3 474370 505828, 5 000205 035765, 5 000354 401947, 5 032307 065425, 8 936017 883171, 8 710624 290092, 8 722700 267966.
  • ISBN-13 : 9 780540 087013, 9 781565 925212.
Tests are needed for each of the other first digits, comparing against printed codes.

Compose HTML string Use DOM methods
Show HTML bars Just below
This page
New page
Options Test colours
UPC
EAN
Data Font  
Px :   Unit bar   Bar height
13 digits :  

2009-05-30,31MS IE 7FirefoxOperaSafariChrome
HTMLJust belowBad 1Good Good Bad 4Good
HTMLThis page OK 2Good Good Good Good
HTMLNew page Good Good Good Good Good
DOM Just belowGood Good Good Good Good
DOM This page Good Good Good Good Good
DOM New page Bad 3Good Good Good Good
  • IE 7 :-
    • 1 : Column of digits; no float effect, no bars. No new style?
    • 2 : After showing the bar code, gives an error message "Permission denied", on return from function NewPage.
    • 3 : Shows only a full-window border, then an error message "No such interface supported".
  • Safari :-
    • 4 : Column of digits; no float effect, no bars. No new style?

Bar Chart

The result should slightly resemble that in GIF, which shows an old version.

Enter a few numbers :-


  W×H :   Base 0 :   Figures : X Y     Mean:
Bar Chart

The principle is to write coloured divs of calculated size and position them absolutely to build the chart. The Mean (red) and Zero (blue) lines are div-border-bottoms, location questionable.

Alternatively, images of colour could be positioned.

Simple Point Drawing

  Enter code below     in "Ref"  
This area is "Ref".

Consider also the canvas element (except in IE≤8), used in Plot Web Site Statistics.

Object Properties

This should show the enumerable properties of an Object and their present values.

 window
 document
 document.body
 document.body.style
 this
 this.form
 the textarea
 


Various Maths Tests

Padding

Unary + - Test

Suffixes

For dates :-

Possibly the best function so far; for all numbers ≥ 0 :-

Pi

John Wallis :-

ii

See Wikipedia and discussion.

To Alter a Function

There may occasionally be a wish to alter the operation of a function without changing its source code; for example, if it is in a frequently updated external library. One reason might be to alter colours; another, to provide translated strings.

This is the initial test, slightly improved; FuncA1 has no arguments.

 

Following test, improved more; function FA2 can have arguments.

   

Day-of-Week Checking

This tests apparent instances of YYYY-MM-DD DoW in texts. It checks that Y-M-D is valid AD Gregorian and that DoW agrees. The year may be any number of digits, but if past about 275000 the date and DoW will not be verified. Paste the input into the textarea. See the code for details. Please do not use this page repeatedly; make a local copy.

Buttons 1 - Site check : pre-process at DOS prompt with (mtr is MiniTrue-32)
  mtr -x+ -o *.htm - "<li><tt>(\d.*)</tt>.*" = \1\r > $X
or
  mtr -x+ -o -c- *.htm - \d\d\d\d-\d\d-\d\d\s*[A-Z][a-z]{2}\W > $X
or
  findstr /r [0-9]-[0-9][0-9]-[0-9][0-9] *.htm > $X
or
  findstr /rn /c:"[0-9]-[0-9][0-9]-[0-9][0-9] [a-z][a-z][a-z]\>" *.htm > $X
or otherwise (maybe SED?). Checks the first date on each line (lines without dates are removed), and shows errors at end of line. Button 1a shows all lines, 1b omits good ones.

Button 2 - Checks an HTML page, or anything else. Each error is reported in a confirm box, with some leading context.


Text Substitution

In the command box, the field separator is TAB; if it is not possible to type it in, then paste or drag it.


 

Note that RegExps are used, and compose the commands accordingly.

XMLHTTP

Not yet working correctly.


KOI8-R to Cyrillic

Enter KOI8-R coded text in the first box, and press the button. The first output is a transliteration to Cyrillic, using a table which is moderately checked. The second output is based on the approximate match between the sounds of KOI8-R and offset ASCII characters. Characters not forming part of a sequence "= Hex Hex" are preserved.

KOI8-R letters occupy C0-FF (in two cases), and are transliterated. The range 00-7F is as ASCII, and so treated. Characters in the range 80-BF are mostly graphics, and are represented as ╬.




This is not a full KOI8-R handler.

List Links

This should automatically list, in alphabetical order, all different links (ignoring anchors) on this page.










Home Page
Mail: no HTML
© Dr J R Stockton, near London, UK.
All Rights Reserved.
These pages are tested mainly with Firefox 3.0 and W3's Tidy.
This site, http://www.merlyn.demon.co.uk/, is maintained by me.
Head.