Hi everyone,

I currently have this script on my page that allows users to add and remove rows in the page. I have a another script that calculates a value on the dynamically generated elements and static ones too.

my problem is, I cant figure out a way to pass in a value for the inputs variable and have it as the base for the row generation...

My question is... how do i pass in a value for the function to begin its creation of the rows.. ? as i have multiple tables with different IDs scattered through my page...

any help greatly appreciated.

ta

<script language="javascript">

var inputs = 4 ;

function addContact(AreaName,AttName1,AttName2)
{

    var table = document.getElementById(AreaName);

    var tr    = document.createElement('TR');
    var td1   = document.createElement('TD');
                td1.setAttribute("width","250");
               
    var td2   = document.createElement('TD');
        td2.setAttribute("width","110");
        td2.setAttribute("align","center");

    var td3   = document.createElement('TD');
        td2.setAttribute("width","110");
        td3.setAttribute("align","center");
       
    var td4   = document.createElement('TD');
   
    var inp1  = document.createElement('INPUT');
    var inp2  = document.createElement('INPUT');
    var inp3  = document.createElement('INPUT');


    if(inputs>=0)
    {
        var img     = document.createElement('IMG');
        img.setAttribute('src', 'images/p6_delete.gif');
        img.onclick = function(){
        removeContact(tr);
    }

//        var img2     = document.createElement('IMG');
//        img2.setAttribute('src', 'images/other.gif');

        td1.appendChild(img);
//        td1.appendChild(img2);


        var img3     = document.createElement('IMG');
        img3.setAttribute('src', 'images/percent.gif');
        img3.setAttribute('height','13');
        img3.setAttribute('width','13');

        td2.appendChild(img3);

        var img4     = document.createElement('IMG');
        img4.setAttribute('src', 'images/dollar.gif');
        img4.setAttribute('height','13');       
        img4.setAttribute('width','13');
       
        td3.appendChild(img4);

    }

    inp1.setAttribute("Name", AttName1 + inputs);
    inp1.setAttribute("class","required");
    inp1.setAttribute("id", AttName1 + inputs);
    inp1.setAttribute("size","2");
    inp1.setAttribute("style","width:35px;");

    inp2.setAttribute("Name", AttName2 + inputs);
    inp2.setAttribute("class","required");
    inp2.setAttribute("id", AttName2 + inputs);
    inp2.setAttribute("size","2");
    inp2.setAttribute("style","width:40px;");

    inp3.setAttribute("Name","Other" + AttName2 + inputs);
    inp3.setAttribute("class","required");
    inp3.setAttribute("id", "Other" + AttName2 + inputs);
    inp3.setAttribute("style","width:170px;");   
    inp3.setAttribute("title","title for the element");

    table.appendChild(tr);
    tr.appendChild(td1);
    tr.appendChild(td2);
    tr.appendChild(td3);
   
    td1.appendChild(inp3);
    td2.appendChild(inp2);    
    td3.appendChild(inp1);
       
   inputs++;

}

function removeContact(tr)
{
    tr.parentNode.removeChild(tr);
}
</script>

. how do i pass in a value for the function to begin its creation of the rows.. ? as i have multiple tables with different IDs scattered through my page...

your question is not clear....
can you explain it,
i think you can pass id and num_row to create row.
whatever you are asking you have already done in your script....

This article has been dead for over six months. Start a new discussion instead.