Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:25:29+00:00 2026-06-18T08:25:29+00:00

To preface this, we are a small organization and this system was built by

  • 0

To preface this, we are a small organization and this system was built by someone long ago. I am a total novice at javascript so I have trouble doing complicated things, but I will do my best to understand your answers. But unfortunately redoing everything from scratch is not really an option at this point.

We have a system of collecting data where clients use a login to verify a member ID, which the system then uses to pull records from an MS Access database to .ASP/html forms so clients can update their data. One of these pages has the following function that runs on form submit to check that data in fields a/b/c sum to the same total as d/e/f/g/h/i. It does this separately for each column displayed (each column is a record in the database, each a/b/c/d/e/f is a field in the record.)

The problem is with this section of the function:


for (var j=0; j<recCnt; j++) {
   sumByType = milesSurf[j] + milesElev[j] + milesUnder[j];
   sumByTrack = milesSingle[j] + milesDouble[j] + milesTriple[j] + milesQuad[j] + milesPent[j] + milesSex[j];

etc.


It should use javascript FOR to loop through each record and test to see if they sum to the same thing.

In Firefox and IE this is working properly; the fields sum properly into “sumByType” and “sumByTrack”. You can see below I added a little alert to figure out what was going wrong:

alert(sumByType + " " + j + " " + recCnt + " " + milesSurf[j] + " " + milesElev[j] + " " + milesUnder[j]);

In Chrome, that alert tells me that the components of “sumByType” and “sumByTrack” (the various “milesXXXXX” variables) are undefined.

My question is: Why in Chrome is this not working properly, when in IE and FFox it is? Any ideas?

Full function code below:


function submitCheck(formy, recCnt) {
//2/10/03: added milesQuad
//---------------checks Q#4 that Line Mileage by type is the same as by track     
var milesElev = new Array(); 
var milesSurf = new Array();
var milesUnder = new Array(); 
var milesSingle = new Array();
var milesDouble = new Array(); 
var milesTriple = new Array();
var milesQuad = new Array();
var milesPent = new Array();
var milesSex = new Array();
var sumByType = 0;
var milesLineTrack = new Array();   //this is for Q5 to compare it to mileage by trackage
var j = 0; var sumByTrack = 0; var liney; var yrOp;
//var str = "document.frm.milesElev" + j;
//alert(str.value);
for (var i in document.frm) {
    if (i.substring(0, i.length - 1) == "milesElev") {
        milesElev[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }   
    if (i.substring(0, i.length - 1) == "milesSurf") {
        milesSurf[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesUnder") {
        milesUnder[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesSingle") {
        milesSingle[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesDouble") {
        milesDouble[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesTriple") {
        milesTriple[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesQuad") {
        milesQuad[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesPent") {
        milesPent[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length - 1) == "milesSex") {
        milesSex[parseInt(i.substring(i.length-1, i.length))] = parseFloat(document.frm[i].value); }
    if (i.substring(0, i.length -1) == "milesLineTrack") {
        milesLineTrack[parseInt(i.substring(i.length-1, i.length))] = document.frm[i].value; }  //12/13/02 used to be parseFloat(document.frm[i].value)
    if (i.substring(0,5)=="Lines") {
        liney = document.frm[i].value;
    if (parseInt(liney)<1 || isNaN(liney)) {
        alert("Each mode must have at least 1 line.  Please correct the value in question #2."); 
        document.frm[i].select(); return false; }}
    if (i.substring(0,8)=="yearOpen") { 
        yrOp = document.frm[i].value;
        if (parseInt(yrOp)<1825 || isNaN(yrOp)) {
            alert("Please enter a year after 1825 for question #3"); 
            document.frm[i].select(); return false; }
    }
}
for (var j=0; j<recCnt; j++) {
    sumByType = milesSurf[j] + milesElev[j] + milesUnder[j];
    sumByTrack = milesSingle[j] + milesDouble[j] + milesTriple[j] + milesQuad[j] + milesPent[j] + milesSex[j];

    //---------------to round sumByTrack and sumByType from a long decimal to a single decimal place, like frm 7.89999998 to 7.9.
    sumByTrack = sumByTrack * 10;
    if (sumByTrack != parseInt(sumByTrack)) {
        if (sumByTrack - parseInt(sumByTrack) >= .5) {
        //round up
            sumByTrack = parseInt(sumByTrack) + 1; }
        else {  //truncate
            sumByTrack = parseInt(sumByTrack); }}
    sumByTrack = sumByTrack / 10;
    sumByType = sumByType * 10;
    if (sumByType != parseInt(sumByType)) { 
        if (sumByType - parseInt(sumByType) >= .5) {
        //round up
            sumByType = parseInt(sumByType) + 1; }
        else {  //truncate
            sumByType = parseInt(sumByType); }}
    sumByType = sumByType / 10;
    //-------------end of rounding ---------------------------

    if (sumByType != sumByTrack) {
        if (isNaN(sumByType)) { 
            sumByType = "(sum of 4.a., b., and c.) "; }
        else {
            sumByType = "of " + sumByType; }
        if (isNaN(sumByTrack)) { 
            sumByTrack = "(sum of 4.d., e., f., g., h., and i.) "; }
        else {
            sumByTrack = "of " + sumByTrack; }
        alert("For #4, the 'End-to-End Mileage By Type' " + sumByType + " must equal the 'End-to-end Mileage By Trackage' " + sumByTrack + ".");
        alert(sumByType + " " + j + " " + recCnt + " " + milesSurf[j] + " " + milesElev[j] + " " + milesUnder[j]);
        return false;
    }
    //alert (milesLineTrack[j] + "  " + milesSingle[j] + "  " + 2*milesDouble[j] + "  " + 3*milesTriple[j] + "  " + 4*milesQuad[j] + "  " + 5*milesPent[j] + "  " + 6*milesSex[j]);
    var singDoubTrip = (milesSingle[j] + 2*milesDouble[j] + 3*milesTriple[j] + 4*milesQuad[j] + 5*milesPent[j] + 6*milesSex[j])
    //----------round singDoubTrip to one digit after the decimal point (like from 6.000000001 to 6.0)
    singDoubTrip = singDoubTrip * 10;
    if (singDoubTrip != parseInt(singDoubTrip)) { 
        if (singDoubTrip - parseInt(singDoubTrip) >= .5) {
        //round up
            singDoubTrip = parseInt(singDoubTrip) + 1; }
        else {  //truncate
            singDoubTrip = parseInt(singDoubTrip); }}
    singDoubTrip = singDoubTrip / 10;
    //----------end round singDoubTrip-----------------------------------------
    if (parseFloat(milesLineTrack[j]) != singDoubTrip) {
        //var mlt = milesLineTrack[j];
        //if isNaN(milesLineTrack[j]) { mlt = 
        alert("For column #" + (j+1) + ", the mainline passenger track mileage of " + milesLineTrack[j] + " must equal the single track plus 2 times the double track plus 3 times the triple track plus 4 times the quadruple track plus 5 times the quintuple track plus 6 times the sextuple track, which is " + singDoubTrip + ".");
        return false; 
    }
}
//---------------------end of checking Q#4----------------

//return false;

}


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:25:30+00:00Added an answer on June 18, 2026 at 8:25 am

    I think for (var i in document.frm) is the problem. You should not enumerate a form element, there will be plenty of unexpected properties – see Why is using "for…in" with array iteration a bad idea?, which is especially true for array-like objects. I can’t believe this works properly in FF 🙂

    Use this:

    var ele = document.frm.elements; // or even better document.getElementById("frm")
    for (var i=0; i<ele.length; i++) {
        // use ele[i] to access the element,
        // and ele[i].name instead of i where you need the name
    }
    

    Also, you should favour a loop over those gazillion of if-statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me preface this question. I have just started using jquery, so please be
Preface: This is not much about how to structure code within files. I have
Preface: This is the first real swing program I have done. I have a
Let me preface this by saying I feel like a moron. I have a
Preface: This has become a quite a long post. While I'm not new to
Let me preface this question by saying that I'd like to avoid using javascript
I'll preface this question with the note that I have looked at this similar
I have to preface this question by saying that I'm aware that hard-coding a
Let me preface this with.. I have extremely limited experience with ASM, and even
I'll preface this by saying I have minimal experience with both Perl and Socket

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.