"I work for a company that takes over the development of certain parts of our partners' websites," Clark S writes. "Often, in the process of porting code, we'll come across some strange and archaic validation files, CSS hacks, and so on. I'm pretty used to seeing bad code (that's why they're paying us, after all), and I can't say I've found anything impressively bad. Don't get me wrong: it's bad... just not The Daily WTF bad."

"Of course, all that changed when I came across the code for a certain new partner. It really threw me for a loop (no pun intended) and taught me that, apparently, I've been using for-loops wrong all these years."

function vFrmUnsubscribe(form)
{
    total = form.length;
        
    var errorMsg = new Array("Please enter a valid Email Address.",
                             "","","","","","","");

    for(var i = 0; i < total; i++)
    {    
        if(i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7)
        {
            continue;
        }
        if(i == 0)
        {
            if(form.elements[i].value == "" || form.elements[i].value.length<1)
            {
                alert(errorMsg[i]);
                form.elements[i].focus();
                return false;
            }
            if(!vEmail(form, i))
            {
                form.elements[i].focus();
                return false;
            }
        }    
        if(form.elements[i].value == "" || form.elements[i].value.length < 1 
                                    || form.elements[i].value == -1)
        {
            alert(errorMsg[i]);
            form.elements[i].focus();
            return false;
        }    
        
    }
    return true;
}

Clark continues, "the moment I saw that, I knew that I finally had something worthwhile to submit. And then I kept scrolling down. Not only was that a standard construct for traversing a form, but I found such joys as the following"

function popupRegulations(popWinURL, popWinTitle, popWinWidth, popWinHeight) 
{ 
  var windowProps = 
      'toolbar=no,status=no,resizable=no,scrollbars=no,menubar=no,width=' 
      + popWinWidth + ',height=' + popWinHeight;
  msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}

function popupDemo(windowURL, windowTitle) 
{
  var windowprops = '
      toolbar=no,status=no,resizable=no,menubar=no,scrollbars=no,width=700,height=423'
  msgWindow = window.open(windowURL, windowTitle, windowprops);
}

function popStepDemo(popWinURL, popWinTitle, popWinWidth, popWinHeight) 
{ 
  var windowProps = 
      'toolbar=no,status=no,resizable=no,menubar=no,width=' 
      + popWinWidth + ',height=' + popWinHeight;
  msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}

function popupWindow(popWinURL, popWinTitle, popWinWidth, popWinHeight) 
{ 
  var windowProps = 
      'toolbar=no,status=no,resizable=no,menubar=no,width=' 
      + popWinWidth + ',height=' + popWinHeight;
  msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}

function popupACTgroups(popWinURL, popWinTitle, popWinWidth, popWinHeight) 
{ 
  var windowProps = 
      'toolbar=yes,status=yes,resizable=yes,scrollbars=1,menubar=yes,width=' 
      + popWinWidth + ',height=' + popWinHeight;
  msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}

function popupWindowScroll(popWinURL, popWinTitle, popWinWidth, popWinHeight) 
{ 
  var windowProps = 
      'toolbar=no,status=no,resizable=no,scrollbars=1,menubar=no,width=' 
      + popWinWidth + ',height=' + popWinHeight;
  msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}

function popupTutorials(popWinURL, popWinTitle, popWinWidth, popWinHeight) 
{ 
  var windowProps = 
      'toolbar=no,status=no,resizable=yes,scrollbars=no,menubar=no,width=' 
      + popWinWidth + ',height=' + popWinHeight;
  msgWindow = window.open(popWinURL, popWinTitle, windowProps);
}

"And if that wasn't enough, this followed."

function isDigit(digit)
{
    var charOk = "0123456789";
    return !(charOk.indexOf(digit) == -1)
}

function isAlphaNumeric(digit)
{
    var charOk = 
      "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return !(charOk.indexOf(digit) == -1)
}

function stripNumber(num)
{    
    if (num==1)
    {
        stripVal = new String(document.frmReportSpam.fldFax.value);
    
        var i = stripVal.indexOf("(",0);
        while(i > -1){
            stripVal = stripVal.replace("(", "")
            i = stripVal.indexOf("(", 0);
        }
        var i = stripVal.indexOf(")",0);
        while(i > -1){
            stripVal = stripVal.replace(")", "")
            i = stripVal.indexOf(")", 0);
        }
        var i = stripVal.indexOf(" ",0);
        while(i > -1){
            stripVal = stripVal.replace(" ", "")
            i = stripVal.indexOf(" ", 0);
        }
        var i = stripVal.indexOf("-",0);
        while(i > -1){
            stripVal = stripVal.replace("-", "")
            i = stripVal.indexOf("-", 0);
        }    
        document.frmReportSpam.fldFax.value = stripVal;
    }
    else
    {
        stripVal = new String(document.frmReportSpam.fldPhone.value);
    
        var i = stripVal.indexOf("(",0);
        while(i > -1){
            stripVal = stripVal.replace("(", "")
            i = stripVal.indexOf("(", 0);
        }
        var i = stripVal.indexOf(")",0);
        while(i > -1){
            stripVal = stripVal.replace(")", "")
            i = stripVal.indexOf(")", 0);
        }
        var i = stripVal.indexOf(" ",0);
        while(i > -1){
            stripVal = stripVal.replace(" ", "")
            i = stripVal.indexOf(" ", 0);
        }
        var i = stripVal.indexOf("-",0);
        while(i > -1){
            stripVal = stripVal.replace("-", "")
            i = stripVal.indexOf("-", 0);
        }    
        document.frmReportSpam.fldPhone.value = stripVal;
    }
    
}

function stripCorpPhone()
{
    stripVal = new String(document.frmCorpIntegration.fldPhone.value);

    var i = stripVal.indexOf("(",0);
    while(i > -1){
        stripVal = stripVal.replace("(", "")
        i = stripVal.indexOf("(", 0);
    }
    var i = stripVal.indexOf(")",0);
    while(i > -1){
        stripVal = stripVal.replace(")", "")
        i = stripVal.indexOf(")", 0);
    }
    var i = stripVal.indexOf(" ",0);
    while(i > -1){
        stripVal = stripVal.replace(" ", "")
        i = stripVal.indexOf(" ", 0);
    }
    var i = stripVal.indexOf("-",0);
    while(i > -1){
        stripVal = stripVal.replace("-", "")
        i = stripVal.indexOf("-", 0);
    }
    document.frmCorpIntegration.fldPhone.value = stripVal;
}

function stripQuotePhone()
{
    stripVal = new String(document.frmQuickQuote.fldPhone.value);

    var i = stripVal.indexOf("(",0);
    while(i > -1){
        stripVal = stripVal.replace("(", "")
        i = stripVal.indexOf("(", 0);
    }
    var i = stripVal.indexOf(")",0);
    while(i > -1){
        stripVal = stripVal.replace(")", "")
        i = stripVal.indexOf(")", 0);
    }
    var i = stripVal.indexOf(" ",0);
    while(i > -1){
        stripVal = stripVal.replace(" ", "")
        i = stripVal.indexOf(" ", 0);
    }
    var i = stripVal.indexOf("-",0);
    while(i > -1){
        stripVal = stripVal.replace("-", "")
        i = stripVal.indexOf("-", 0);
    }
    document.frmQuickQuote.fldPhone.value = stripVal;
}

"On the bright side," Clark added, "at least I finally found something impressively bad."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!