Need help with java script

Discussion in 'JavaScript' started by ichybanoff, May 11, 2007.

  1. #1
    i am working on an application and i create a tr and a td from javascript in witch i insert some information...i also have a text box in a jsp form and when i press a letter the table is pupped up....i need to navigate in that table...how can i set Attributes like onkeydown to a tr or a td from javascript...
    the code looks like this:
    jsp: .....
    <form name="autofillform" action="autocomplete" method="get">
    <table>
    <tr>
    <td>
    <input type="text" size="20" autocomplete="off" id="complete-field" name="addressee_contact" onkeyup="doCompletion();" onkeydown="return checkKey(this.form)">
    </td>
    </tr>
    <tr>
    <td id="auto-row" colspan="2">&nbsp;
    <td/>
    </tr>
    </table>
    </form>
    <%--<ajax:autocomplete source="complete-field" target="complete-field" baseurl="/miruGlobal/autocomplete.do" parameters="complete-field={id}" minimumCharacters="1" parser="new ResponseXmlToHtmlListParser()"/>--%>
    </td>
    </tr>
    <tr>
    <td style="vertical-align: top; text-align: justify;">
    </td>
    <td style="vertical-align: top;">
    <div class="tableContainer" style="position: absolute; border : 1px black" id="menu-popup">
    <table class="scrollTable" id="tableContent" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="120px" height="35px" style="background-color: rgb(255, 255, 255)">
    <table id="completeTable" cellpadding="0" cellspacing="0">
    </table>
    </td>
    </tr>
    </table>
    </div>
    </td>
    </tr>
    .......

    and js:
    function appendDest(Name,idAddressee) {
    var numeCell;
    var row;
    var nameCell;
    if (isIE) {
    row = completeTable.insertRow(completeTable.rows.length);
    nameCell = row.insertCell(0);
    } else {
    row = document.createElement("tr");
    nameCell = document.createElement("td");
    row.appendChild(nameCell);
    completeTable.appendChild(row);
    }
    row.className = "popupRow";
    nameCell.setAttribute("background-color", "white");


    var linkElement = document.createElement("a");
    linkElement.className = "popupItem";
    linkElement.setAttribute("href", "autocomplete.do?action=lookup&id=" + idAddressee);
    linkElement.appendChild(document.createTextNode(Name));
    nameCell.appendChild(linkElement);
    }

    function checkKey(form){
    var key = event.keyCode;
    if(key == 38){
    if(document.all.completeTable.rowIndex != 0){
    alert(document.all.completeTable.rowIndex);
    return false
    }
    else{ alert("Index la 0");}
    }
    else if(key == 40){
    if(document.all.completeTable.rowIndex != document.all.completeTable.rows.length - 1){
    alert(document.all.completeTable.rowIndex);
    document.all.completeTable.rows[0].cells[0].children[0].focus();
    return false
    }else{alert("Index bound")}
    }
    }
     
    ichybanoff, May 11, 2007 IP
  2. ozab

    ozab Well-Known Member

    Messages:
    444
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Do you still need help with this. PM me if you need help.
     
    ozab, May 18, 2007 IP