Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31192

HTML/Javascript Data Interfaces

From MikeCopeland <mrc2323@cox.net>
Newsgroups comp.lang.javascript
Subject HTML/Javascript Data Interfaces
Date 2016-08-28 12:47 -0700
Organization A noiseless patient Spider
Message-ID <MPG.322ceda719712dcf9896ce@news.eternal-september.org> (permalink)

Show all headers | View raw


   I have inherited a Web application that's comprised of a set of 10 
HTML/Javascript apps and a "main" page that links to the 10 HTML code 
pages.  Each of the 10 pages has a corresponding Javascript code page 
that has 2 functions.  I'd like to combine and compact all this code 
into fewer source files (for maintenence), as well as reduce redundant 
code.
   My thought is to have a single Javascript file (all processing is 
identical, but the data array is different for each).  In order to do so 
I must declare the array values in the calling HTML (I'm unsure how to 
do this) and call the single Javascript cocde with an additional 
argument (I have no idea how to do this).  In the code below, the data 
array called "Distances" is the app-specific code that I intend to move 
to the HTML code (not know how to declare it, though), and the call from 
there is:

  <input type="button" value="Compute Distance" 
       onClick="Process1(document.Start.Start_Point,  
document.End.End_Point, this.form, SOMETHING)">

   The Web site is: http://mrc5305.com/rp_history/canals.htm

   I hope I've made my query clear.  Please advise.  TIA
////////////////////////////////////////////////////////////////////////
    var Total = 0.0;
function roundOff(value, precision)
{
    var prior    = value;                         // save incoming value
    value        = ""+value                    //convert value to string
    precision    = parseInt(precision);
    var whole    = ""+Math.round(value*Math.pow(10, precision));
    var decPoint = whole.length - precision;

    if(decPoint != 0)
    {
        result = whole.substring(0, decPoint);
        result += ".";
        result += whole.substring(decPoint, whole.length);
    }
    else
    {
        if(prior > 0.9) result = whole;
        else            result = "."+whole;
    }
    return result;
}  // roundOff

function Process1(S,E, form1)
{
    Distances = new Array(0.57, 0.45, 0.62, 0.79, 0.52, 1.14, 0.36, 
0.24,
                     0.55, 1.07, 1.12, 0.98, 1.00, 1.09, 0.71, 0.45,
                     1.33, 1.14, 1.02, 1.14);
    var start = S.selectedIndex;
    var end   = E.selectedIndex;
    Total     = 0;
    if(start < end)
       for(var i = start; i < end; i++)
       { 
          Total = Total+Distances[i];
       }
    else
       for(var i = start; i > end; i--)
         { 
           Total = Total+Distances[i];
         }
    Total = roundOff(Total, 2);
    w1    = ""+Total*1+" Miles";        
  	form1.p2p.value = w1;
    w1    = ""+Total*2+" Miles";
  	form1.loop.value = w1;
    return;
}  // Process1




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Back to comp.lang.javascript | Previous | NextNext in thread | Find similar | Unroll thread


Thread

HTML/Javascript Data Interfaces MikeCopeland <mrc2323@cox.net> - 2016-08-28 12:47 -0700
  Re: HTML/Javascript Data Interfaces Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-28 21:12 +0100
    Re: HTML/Javascript Data Interfaces MikeCopeland <mrc2323@cox.net> - 2016-08-28 15:00 -0700
  Re: HTML/Javascript Data Interfaces Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-30 12:45 +0200
    Re: HTML/Javascript Data Interfaces John Harris <niam@jghnorth.org.uk.invalid> - 2016-08-30 19:33 +0100

csiph-web