Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: HTML/Javascript Data Interfaces Date: Sun, 28 Aug 2016 21:12:27 +0100 Organization: A noiseless patient Spider Lines: 55 Message-ID: <87shtofyac.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="9703"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JEjHE1HVIm6i4qnjocVVi+AxNndEeREo=" Cancel-Lock: sha1:h5MxNgaYmdr3o0HKEpS461rNWj8= sha1:F5zCq0d6WannWEvB6Vbas4MHtB4= X-BSB-Auth: 1.11d782e28708930d882b.20160828211227BST.87shtofyac.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:31194 MikeCopeland writes: > 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: > > onClick="Process1(document.Start.Start_Point, > document.End.End_Point, this.form, SOMETHING)"> > 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); There are so many ways to do this it's hard to know what the best method is. Are the 10 HTML pages generated from some master data? I think you already have the gist of one reasonable approach. You'd change the function to function Process1(S,E, form1, Distances) and write the array into the call in the HTML file: You can write [0.57, 0.45, ...] instead of new Array(0.57, 0.45, ...) if you prefer. -- Ben.