JavaScript
 

Home
Up
Time-clock, Attendance
Web Data Extractor
Polaris FTP
Polaris Stamp
Polaris Word Count
AS/400 Data Browser
PC File CR Inserter
PC File Merger
Order via PayPal
Purchase Order
Free Downloads
Support Request
Contact Us

Copyright © 2004
by Polaris Computing.
All rights reserved.

 

 

JavaScript Code for ISBN Conversion

Following is a JavaScript function that converts ISBN-10 to ISBN-13.  Your Web programs may need it if they accept ISBN's as input.

The following code is written with Microsoft Script Editor and FrontPage.

Language JavaScript
Development Tool Microsoft Script Editor with FrontPage
Disclaimer:  All sample code contained herein is provide to you  "AS IS."  ALL IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF THE MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE EXPRESSLY DISCLAIMED.

<script id=clientEventHandlersJS language=javascript>
<!--

function BtnConvert_onclick() {
  var i = 0;
  var v = 0;
  var n = 0;
  var c = "";
  var Result = "";
  var s12 = "";
  var ISBN10 = document.FrmConv.TxtISBN10.value;
  var len = ISBN10.length;
  if (len<9 || len>10) Result = "ERROR";
  else {
    s12 = "978" + ISBN10.substring(0, 9);
    for (i=0; i<12; i++) {
      if (Result=="") {
        c = s12.charAt(i);
        if (c>="0" && c<="9") {
          v = c - 0;
          if ((i % 2)!=0) v = 3 * v;
          n = n + v; 
        }
        else Result = "ERROR"  
      }
    }
    if (Result=="") {
      n = n % 10;
      if (n!=0) n = 10 - n;
      Result = s12 + n; 
    }
  }
  document.FrmConv.TxtISBN13.value = Result;
}

//-->
</script>