SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    asign uniq id to cloned input

    hi!
    i use this code to clone the exsist table cols and rows!
    Code:
    function addColumnsAndRows(iTableID, iRowsAdd, iColsAdd){
    var objTable = document.getElementById(iTableID);
    if(objTable){
    var ndTableRows = objTable.tBodies[0].rows;
    for(var i = 0; i < iRowsAdd; i++){
    var ndNewRow = ndTableRows[0].cloneNode(true);
    clearClonedInputValues(ndNewRow);
    objTable.tBodies[0].appendChild(ndNewRow);
    }
    for(var j = 0; j < iColsAdd; j++){
    for(var i = 0; i < objTable.tBodies[0].rows.length; i++){
    var ndNewCol = ndTableRows[0].cells[0].cloneNode(true);
    clearClonedInputValues(ndNewCol);
    ndTableRows[i].appendChild(ndNewCol);
    }
    }
    }
    initInputs();
    }
    now...
    into every cell there is a input type text which is cloned too...
    how to add a uniq id to cloned textfield into the cells?
    any suggestion?
    thanx in advance!

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A unique id could be:

    iTableID + "" + thisRowNum + "" + thisColNum

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx mike...
    how to insert it into that code?
    regards

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a quick attempt. I haven't tested it.
    Code:
    function addColumnsAndRows(iTableID, iRowsAdd, iColsAdd)
    {
      var objTable = document.getElementById(iTableID);
      if(objTable) {
        var i, j, ndNewRow, ndNewCol, iColNum; // mf
        var ndTableRows = objTable.tBodies[0].rows;
        for (i = 0; i < iRowsAdd; i++) {
          ndNewRow = ndTableRows[0].cloneNode(true);
          clearClonedInputValues(ndNewRow);
          objTable.tBodies[0].appendChild(ndNewRow);
        }
        iColNum = ndTableRows[0].cells.length; // mf
        for (j = 0; j < iColsAdd; j++) {
          for (i = 0; i < objTable.tBodies[0].rows.length; i++) {
            ndNewCol = ndTableRows[0].cells[0].cloneNode(true);
            ndNewCol.id = iTableID + i + "" + iColNum; // mf
            clearClonedInputValues(ndNewCol);
            ndTableRows[i].appendChild(ndNewCol);
          }
          ++iColNum; // mf
        }
      }
      initInputs();
    }

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i understand that gives new id to a td?
    Code:
    function addColumnsAndRows(iTableID, iRowsAdd, iColsAdd)
    {
      var objTable = document.getElementById(iTableID);
      if(objTable) {
        var i, j, ndNewRow, ndNewCol, iColNum; // mf
        var ndTableRows = objTable.tBodies[0].rows;
        for (i = 0; i < iRowsAdd; i++) {
          ndNewRow = ndTableRows[0].cloneNode(true);
          clearClonedInputValues(ndNewRow);
          objTable.tBodies[0].appendChild(ndNewRow);
        }
        iColNum = ndTableRows[0].cells.length; // mf
        for (j = 0; j < iColsAdd; j++) {
          for (i = 0; i < objTable.tBodies[0].rows.length; i++) {
            ndNewCol = ndTableRows[0].cells[0].cloneNode(true);
            ndNewCol.id = iTableID + i + "" + iColNum; // mf
            clearClonedInputValues(ndNewCol);
            ndTableRows[i].appendChild(ndNewCol);
          }
          ++iColNum; // mf
        }
      }
      initInputs();
    }
    u see i have a clearClonedInputValues(ndClear)....
    so there i made something like this..
    Code:
      function clearClonedInputValues(ndClear){
     var mateM = String(Math.random()).substr(2,3);
     var ndlstInputs = ndClear.getElementsByTagName("input");
     var ndlstImg = ndClear.getElementsByTagName("img");
     for(var i = 0; i < ndlstInputs.length; i++) {
     ndlstInputs[i].value = "";
     ndlstInputs[i].setAttribute('id', 'mateM');
    }
     for(var j = 0; j < ndlstImg.length; j++) {
     ndlstImg[j].setAttribute('onClick', 'showPopup(\'nameFieldPopup\', event);getVal(mateM)');
    }
     }
    as u can see i tried to add there a new id for the input and the same value for the function getVal. couse it take a value from textfield and put into another textfield on a popup layer!
    Code:
    function getVal(num) {
    if(document.getElementById(num).value == "") {
    document.getElementById("valz").innerHTML = "The value is empty!";
    } else {
    document.getElementById("valz").innerHTML = document.getElementById(num).value;
    }
    }
    now as u can see i miss the iColNum to make a uniqid into clearCloned.....(ndClear)can we pass your aproach to that function'?
    suggestions?
    thanx in advance!
    Last edited by reminder; Dec 2, 2004 at 11:28.


Bookmarks

Posting Permissions

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