Javascript help...frusteration setting in!

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

Code: [ Select ]
function buildLetter(){
    var form = document.Message;
    var reason;
    var disputeReason = "";
    var theReason;
    for (i = 0; i < form.cb.length-1; i++){
        if(form.cb[i].checked){
            reason = form.cb[i].value;
        }
        if (reason != ""){
            theReason = getReason(why, reason);
        }else if (reason == ""){
            theReason = "Other";
        }
        disputeReason = disputeReason + theReason;
    }
    alert(disputeReason);
}
  1. function buildLetter(){
  2.     var form = document.Message;
  3.     var reason;
  4.     var disputeReason = "";
  5.     var theReason;
  6.     for (i = 0; i < form.cb.length-1; i++){
  7.         if(form.cb[i].checked){
  8.             reason = form.cb[i].value;
  9.         }
  10.         if (reason != ""){
  11.             theReason = getReason(why, reason);
  12.         }else if (reason == ""){
  13.             theReason = "Other";
  14.         }
  15.         disputeReason = disputeReason + theReason;
  16.     }
  17.     alert(disputeReason);
  18. }


this code gives me pretty much what I want w/ one exception. It alerts (for purposes of testing only) the string 1234xxxxxxxxxxx. Assuming that 1-x are unique pieces of data.

Maybe that's not a very clear description of my problem. See that x value...whatever it may be...it keeps repeating it.

PS: My catch-all if the reason is "" is Other...and that alerts back as a repeating UNDEFINED.

I'm scratchin my head here!!!!!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

OK! I just figured out what it's doing

The loop runs 10 times. It writes 1234xxxxxx. The # of x's represents how many times it looped finding nothing.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

Code: [ Select ]
if (reason != ""){
     theReason = getReason(why, reason);
   }else if (reason == ""){
     theReason = "Other";
   }
  1. if (reason != ""){
  2.      theReason = getReason(why, reason);
  3.    }else if (reason == ""){
  4.      theReason = "Other";
  5.    }


This is the part that doesn't work...hmmm...i guess thinking out loud is helping here. I've worked on this tiny azz code for like 4 hrs. now.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

OK...after pulling some hair out. i FINALLY fixed it...here's the repaired code.

Code: [ Select ]
function buildLetter(){
    var form = document.Message;
    var reason;
    var disputeReason = "";
    var theReason;
    for (i = 0; i < form.cb.length-1; i++){
        if(form.cb[i].checked){
            reason = form.cb[i].value;
            theReason = getReason(why, reason);            
        }else if (form.cb[i].checked == false){
            theReason = "";
        }
        disputeReason = disputeReason + theReason;
    }
    alert(disputeReason);
}
  1. function buildLetter(){
  2.     var form = document.Message;
  3.     var reason;
  4.     var disputeReason = "";
  5.     var theReason;
  6.     for (i = 0; i < form.cb.length-1; i++){
  7.         if(form.cb[i].checked){
  8.             reason = form.cb[i].value;
  9.             theReason = getReason(why, reason);            
  10.         }else if (form.cb[i].checked == false){
  11.             theReason = "";
  12.         }
  13.         disputeReason = disputeReason + theReason;
  14.     }
  15.     alert(disputeReason);
  16. }


The problem ended up being that it was mishandeling unchecked check boxes. All is well now. Thank everyone for watching me bounce ideas off the wall.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I missed the banging the head off the wall part, but nice to see you worked it through and thanks for including the solution!
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

Glad we could help! =]
.c

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 115 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.