www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need help fixing three errors in the homework

  1. #1
    Join Date
    Jul 2014
    Posts
    1

    Need help fixing three errors in the homework

    This is the assignment below it comes back with three errors right now. I could not figure out how to fix them. Can anyone help??

    Code:
    /*
       Global Variables:
       filterTable
          References the the table containing the filter data
    
       filterCols
          References the col elements within the filter table
    
       filterHead
          References the head section of the filter table
    
       filterBody
          References the body section of the filter table
    
    
       Function List:
       addEvent(object, evName, fnName, cap)
          Adds an event hander to object where evName is the name of the event,
          fnName is the function assigned to the event, and cap indicates whether
          event handler occurs during the capture phase (true) or bubbling
          phase (false)
    
       isUnique(matchValue, arrList)
          Returns a value true if matchValue is found in the array, arrList, otherwise
          it returns the value, false.
    
       init()
          Initiates the filter table, generating the selectin lists, and creating event 
          handlers for each select element and counting the number of records in the 
          data table
    
       countRecords()
          Counts the number of visible rows in the data table
    
       addTotalsRow()
          Adds a new row to the top of the header section displaying the total
          number of records in the table
    
       createSelectionList(colIndex)
          Creates a selection list populated with option text matching the
          unique values in the table column indicated by colIndex
    
       addUniqueOptions(selectionList, colIndex)
          Adds option elements to the selectionList with the text of each 
          option reflecting a unique value from the data column. The index
          parameter specifies the index of the column from which the 
          option values are drawn.
    
       resetTable()
          Resets the data table, displaying all table rows
    
       doFilter()
          Filters the data table based on the values selected in the drop-down 
          selection lists. Also updates the record count.
    
       filterColumn(colIndex, fText)
          If the cell value from the current column does not equal the value
          of fText, this function hides the table row of which the table cell is part.
    
    
    */
    
    function addEvent(object, evName, fnName, cap) {
       if (object.attachEvent)
           object.attachEvent("on" + evName, fnName);
       else if (object.addEventListener)
           object.addEventListener(evName, fnName, cap);
    }
    
    function isUnique(matchValue, arrList) {
       var joinArray = "^"+arrList.join("^")+"^";
       var index = joinArray.indexOf("^"+matchValue+"^");
       if (index == -1) return true;
       else return false;
    }
    
    var filterTable; //references web table 
    
    var filterCols;  //references col elements  table
    
    var filterHead;  //references head section 
    
    var filterBody;   // references  tbody element in filter table  
    
    
    addEvent(window, "load", init, false); 
    
    function init() {
    
    var filterTable = document.getElementById("filterTable");    
        
    var filterCols = document.getElementsByTagName("col");
    
    var filterHead = document.getElementsByTagName("tHead");
    
    var filterBody = document.getElementById("filterTable").tBodies;
        
    var newRow = document.createElement("tr");
    
    for (var i = 0; i < filterCols.length; i++) {
        
    var newCell = document.createElement("th");
    
    newCell.style.align = "left";
    
    newCell.style.color = "black";
    
    newCell.style.backgroundColor = "white";
    
    if (filterCols[i].className == "filter") {
    
    //this line has an error  
    var newSelect = createSelectionList(i);
        
    newCell.appendChild(newSelect);}
    
    newRow.appendChild(newCell);
    
        
    }
    
        
    filterHead.appendChild(newRow);    
    
        addTotalsRow();
    }
    
    function countRecords() {
    
    var rowCount = 0;
    
    for (var i = 0; i < filterBody.rows.length; i++) {
       
        if (filterBody.rows[i].style.display == "") {
            
            rowCount++;
        }
    }
    
    
        return rowCount;
    }
    
    
    function addTotalsRow() {
        
    var newRow = document.createElement("tr");
        
    var newCell = document.createElement("td");
     
            newCell.colSpan = 7; 
    
            newCell.innerHTML = "Matches Found: " + countRecords();
    
            newRow.appendChild(newCell);
    
            filterHead.insertBefore(newRow, filterHead.firstChild);
    
    }
    
    function createSelectionList(colIndex) {
    
    var newSelect = document.createElement("select");
    
    newSelect.cIndex = colIndex;
    
    var blankOption = document.createElement("option");
    
    blankOption.innerHTML = "";
    
    newSelect.appendChild(blankOption);
    
    //this line which calls on a function comes back with an error
    
    addUniqueOptions(newSelect, colIndex);
    
    newSelect.width.style = "100%";
    
    addEvent(newSelect, "onchange", doFilter, false);
    
    return newSelect;
    }
    
    function addUniqueOptions(selectionList, colIndex) {
    
    var uniqueList = new Array();
    
    //i get an error in the line below  
    
    for (var i = 0; i < filterBody.rows.length; i++) {
    
    var rowCell = filterBody.rows[i].cells[colIndex];
    
    var cellValue = rowCell.innerText || rowCell.textContent;
    
    isUnique(cellValue, uniqueList);
    
    if (isUnique == true) {
    
    uniqueList.push(cellValue);
    }
    }
    
        
    uniqueList.sort();
    
    for (var i = 0; i < uniqueList.length; i++) {
    
    
    var option = document.createElement("option");
    
    option.innerHTML = uniqueList[i];
    
    selectionList.appendChild(option);
    }
    
    }
    
    
    function resetTable() {
    
    for ( var i = 0; i < filterBody.rows.length; i++) {
    
        filterBody.rows[i].style.display = "";
    }
    }
    
    function doFilter() {
    
    resetTable();
        
    var allSelects = document.getElementsByTagName("select");
    
    for ( var i = 0; i < allSelects.length; i++) {
    
    var filterIndex = allSelects[i];
    
        var filterText = allSelects.text; 
    
        var colIndex = filterIndex.cIndex; {
    
    if (filterText !="")  {
    
    filterColumn(colIndex, filterText);
        }
    
      filterHead.rows[0].cells[0].innerHTML = "Matches Found: " + countRecords();
        
    }
    
    }
    }
    
    function filterColumn (colIndex, fText) {
    
    for (var i = 0; i < filterBody.rows.length; i++) {
    
    var rowCell = filterBody.row[i].cells[colIndex];
    
    var rowCellText = rowCell.inndrText || rowCell.textContent;
        
    if (rowCellText != fText) {
        
    filterBody.rows[i].style.display = "none";
    }
    }
        
    
    //
        
    }
    Thank You

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,360
    Does help if you tell people what the three errors are rather than expect people to wade through code. What is better is for the entire web page and all the line numbers the errors appear on are included, this speeds up any pointers towards help.

    I did notice whilst indenting the above code that you have some further errors in your code and use of functions.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles