-1

hey I'm just having some trdouble with an onclick call. its being called before it iss. not really sure whats wrong with it. im also passing it in a function with arg so that the value i is assigned to it for the loop. i tried it without it and it just got assigned the greatest i value

function displaySearch(xmlhttp){
var divTable = document.getElementById('table')
divTable.innerHTML = "<table id='tableSearch' name='tableSearch' border='1'><tr><th>Course</th><th>Number</th><th>Tut/Grp</t    <th>Email</th><th>Cap</th><th>Registered</th><th>Register</th></tr></table>"
var div = document.getElementById('table')
var table = document.getElementById('tableSearch')
var res = xmlhttp.responseXML
var e = res.getElementsByTagName('element')
for(var i = 0; i < e.length; i++){
    var splitResult = e[i].textContent.split('#')
    var course = splitResult[0]
    var num = splitResult[1]
    var tut = splitResult[2]
    var email = splitResult[3]
    var capacity = splitResult[4]
    var users = splitResult[5]      
    var rowCount = table.rows.length
    var row = table.insertRow(rowCount)
    var cell1 = row.insertCell(-1)
    cell1.id = "1" + i
    cell1.innerHTML = course
    var cell2 = row.insertCell(-1)
    cell2.id = "2" + i
    cell2.innerHTML = num
    var cell3 = row.insertCell(-1)
    cell3.id = "3" + i
    cell3.innerHTML = tut
    var cell4 = row.insertCell(-1)
    cell4.id = "4" + i
    cell4.innerHTML = email
    var cell5 = row.insertCell(-1)
    cell5.id = "5" + i
    cell5.innerHTML = capacity
    var cell6 = row.insertCell(-1)
    cell6.id = "6" + i
    var registered = users.split('/')
    if(users != ""){
        //cell6.innerHTML = users
        cell6.innerHTML = "<ul>"
        for(var k = 0; k < registered.length; k++){
            var p = "<li>" + registered[k] + "</li>"
            cell6.innerHTML = cell6.innerHTML + p
        }
        cell6.innerHTML = cell6.innerHTML + "</ul>"
    }
    var cell7 = row.insertCell(-1)
    cell7.id = "7" + i
    /*if(capacity == 1){
        var reg = document.createElement('input')
    reg.type = 'button'
    reg.value = "Register"
    reg.id = i
    reg.name = i
    var createReg = registerCourse(arg)
    reg.onclick = function(){createReg(cell7.id)}
    var cell = "row"+i
    cell7.appendChild(reg)
    }*/
    if(registered.length == capacity){
        cell7.innerHTML = "FULL"
    }
    else{
    var reg = document.createElement('input')
    reg.type = 'button'
    reg.value = "Register"
    reg.id = i
    reg.name = i
    var createReg = function(arg){registerCourse(arg)}
    reg.onclick = createReg(cell7.id)
    var cell = "row"+i
    cell7.appendChild(reg)}
}

}

Edited by mavis310: forgot info

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Troy III
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.