Path: csiph.com!news.freedyn.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: HTML/Javascript Data Interfaces Date: Tue, 30 Aug 2016 12:45:01 +0200 Organization: PointedEars Software (PES) Lines: 131 Message-ID: <1995644.ElGaqSPkdT@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1472553904 31476 eJwNxckBwCAMA7CVMHGOdUjA+4/Q6iO3QEwyPOhy2Uue/CNxUQzNfrSaM1FoJYRZ3WCuvFsfHJsRKg== (30 Aug 2016 10:45:04 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 30 Aug 2016 10:45:04 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwVx8ERACEIBLCWBGFXygGV/kvw7pWJTwg2DQ7z9o5VWm2yIuuzWDt4Zpx5Ad5wtf+5IZF+vVp1NYkcRhn9AGKoFYM= X-NNTP-Posting-Host: eJwFwQEBwCAMAzBL/KPtkMMK8y+BBMGP1iQ40WhluwaRru6D3FuyFO3csyruGRe/FkxiuR41WhHb Cancel-Lock: sha1:bemhpWRnE90R2VcXyfkUJcPHAYY= Xref: csiph.com comp.lang.javascript:31216 MikeCopeland wrote: > 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) Simplest solution: Better solution: Pass the array as an argument to the function. > and call the single Javascript cocde with an additional argument (I have > no idea how to do this). RTFFAQ or employ someone with the expertise. There are *starving* *talented* developers out there. > […] > onClick="Process1(document.Start.Start_Point, > document.End.End_Point, this.form, SOMETHING)"> Should probably be at which point you should find a way to get rid of the spaghetti code. Do you really need three forms? > The Web site is: http://mrc5305.com/rp_history/canals.htm So I guessed right. The person writing this had no clue what they were doing. You only need one form, and then which then reduces to and ultimateily to because the logic should be in the function (which should be renamed “process1” as it is not a constructor, probably something more descriptive). Unless the forms are that dissimilar that this is not an option. > I hope I've made my query clear. Please advise. TIA ^^^^^^^^^^^^^^^^^^^ Start from scratch. You’re welcome. > //////////////////////////////////////////////////////////////////////// > var Total = 0.0; > function roundOff(value, precision) > { > var prior = value; // save incoming value > value = ""+value //convert value to string “value” probably is a String already. But since “value” is *only* used in a *multiplication* operation, what is the point of converting it to *String*? > […] Ouch. There are so many things wrong with this code that I do not know where to begin. > 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); > […] > w1 = ""+Total*1+" Miles"; var w1 = Total + " Miles"; > form1.p2p.value = w1; See above. > form1.loop.value = w1; See above. > return; ^^^^^^^ > } // Process1 ^ I leave the rest of the code review to JSHint: > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus This was not an e-mail; please disable the spam. Also, a space character is missing in your name. Inserting it in the right place will increase the number of people reading you and willing to help you. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.