Dynamic Table problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • junal
    New Member
    • Jan 2007
    • 22

    Dynamic Table problem

    Hi,
    Im working on HTML table. There is two list items. Lets say both items are kind of process. So every time I press the button both list will be selected n they will be listed in a table(in a new row). User can select as many as they want. Now, there will be another button which will bring each selected process in a column, that means row will go to column with the selected value. I have done it but dunno know how to get those listed value in columns. Plz help me !!
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    ??? Sorry I can not follow any of that

    If all you need to to is move text from one place to another it would be something like :

    <div id="div1" >Some text string</div>
    <div id="div2" ></div>

    <script>
    var textToMove = document.getEle mentById("div1" ).innerHTML'';
    document.getEle mentById("div2" ).innerHTML = textToMove;
    </script>

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by junal
      Hi,
      Im working on HTML table. There is two list items. Lets say both items are kind of process. So every time I press the button both list will be selected n they will be listed in a table(in a new row). User can select as many as they want. Now, there will be another button which will bring each selected process in a column, that means row will go to column with the selected value. I have done it but dunno know how to get those listed value in columns. Plz help me !!
      Not sure if I've understood your problem. Perhaps if you post your code, it might help.

      Comment

      • junal
        New Member
        • Jan 2007
        • 22

        #4
        Originally posted by acoder
        Not sure if I've understood your problem. Perhaps if you post your code, it might help.
        actually i have solved the problem. here is the code...hope u can understand what i meant....but i got another problem with it. it doesnt work in IE but in firefox :(.....can u help me ?....thx for the reply.

        [HTML]<HTML><HEAD>
        <TITLE>test</TITLE>
        <script LANGUAGE="JavaS cript">

        var col1=new Array();
        var col2=new Array();
        var x=0;

        __uid = 0;
        __uid1 = 0;

        doc = document;

        function addRowTo(id) {
        x++;
        var newrow;
        var tbl;
        var newcol , newinput;
        if(x==1)
        {
        tbl = doc.getElementB yId(id);
        newrow = doc.createEleme nt("TR");
        newcol = doc.createEleme nt("TD");
        newinput = doc.createEleme nt("input");
        newinput.value = "Process";
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);
        newcol = doc.createEleme nt("TD");
        newinput = doc.createEleme nt("input");
        newinput.value = "title";
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);


        tbl.appendChild (newrow);
        __uid++;
        }
        tbl = doc.getElementB yId(id);
        //create a new row
        newrow = doc.createEleme nt("TR");

        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "date"+__ui d;
        newinput.size = 20;
        newinput.value = doc.main.date.v alue;
        col1[x]=newinput.value ;
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);


        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "end"+__uid ;
        newinput.size = 20;
        newinput.value = doc.main.end.va lue;
        col2[x]=newinput.value ;
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);


        tbl.appendChild (newrow);
        __uid++;


        document.main.d ate.value = '';

        document.main.e nd.value = '';

        document.main.d ate.focus();
        //alert(x);

        }


        function generateTable(i d){

        var hmrc=0;
        var h=0;
        var newrow;
        var tbl;
        var newcol , newinput;

        var loopcounter=0;

        tbl = doc.getElementB yId(id);
        //create a new row
        newrow = doc.createEleme nt("TR");
        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "head";
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);


        while ( loopcounter<x ){

        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "newrow1table"+ __uid1;
        newinput.size = 20;
        newinput.value = col1[loopcounter+1];
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);
        loopcounter++;

        }
        tbl.appendChild (newrow);
        __uid1++;

        loopcounter=0;
        newrow = doc.createEleme nt("TR");
        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "head";
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);

        while ( loopcounter<x ){

        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "newrow2table"+ __uid1;
        newinput.size = 20;
        newinput.value = col2[loopcounter+1];
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);
        loopcounter++;

        }
        tbl.appendChild (newrow);
        __uid1++;

        h=parseInt (doc.newtable.h mr.value);
        //alert(h);

        hmrc++;

        while (hmrc<=h){

        loopcounter=0;

        newrow = doc.createEleme nt("TR");
        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "head"+hmrc ;
        newinput.value= "Test "+hmrc;
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);

        while ( loopcounter<x ){

        newcol = doc.createEleme nt("TD");
        newcol.width = 200;
        newinput = doc.createEleme nt("input");
        newinput.name = "env"+loopcount er;
        newinput.size = 20;
        newinput.value = "";
        newcol.appendCh ild(newinput);
        newrow.appendCh ild(newcol);
        loopcounter++;

        }

        tbl.appendChild (newrow);
        hmrc++;
        }


        }
        </script>
        </HEAD>
        <body>
        <form name="main" method='post'>
        <table id="tbl1">
        <tbody id="tbl1body">

        <tr>
        <td><label>
        <select name="date">
        <option>Seelc t</option>
        <option>Se</option>
        <option>Wa</option>
        </select>
        </label>

        </td><td><label>
        <select name="end">
        <option>Seelc t</option>
        <option>WM</option>
        <option>WS</option>
        </select>

        </label>

        <a href="#" onClick="addRow To('tbl1body')" >
        <img border=0 src="/images/add.gif"></a>
        </td>
        </tr>

        </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp; </p>
        <table id="myTable">
        </form>
        <form name="newtable" method="post" action="">
        <label>
        <p>
        <input name="hmr" type="text" value="3">
        </p>
        <p> <input type="button" name="Button" value="TEst" onClick="genera teTable('myTabl e')">
        </p>
        </label>


        </table>


        </form>
        <p>&nbsp;</p>
        </html>[/HTML]
        Last edited by acoder; Jan 29 '07, 07:27 PM. Reason: Code in tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Your table start tag with id myTable is in the wrong place. Put it after the second form together with the table closing tag:
          [HTML]<table id="myTable">
          </table>[/HTML]

          Comment

          • junal
            New Member
            • Jan 2007
            • 22

            #6
            Originally posted by acoder
            Your table start tag with id myTable is in the wrong place. Put it after the second form together with the table closing tag:
            [HTML]<table id="myTable">
            </table>[/HTML]
            still not working :(.....

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              In IE, you need a tbody tag within the table tags, as you have done with the first table. Then pass the id of the tbody instead of 'myTable' into the generateTable() function. It worked for me on IE6.

              Comment

              • junal
                New Member
                • Jan 2007
                • 22

                #8
                Originally posted by acoder
                In IE, you need a tbody tag within the table tags, as you have done with the first table. Then pass the id of the tbody instead of 'myTable' into the generateTable() function. It worked for me on IE6.
                Thank You so much!...its working :)...now i got another question! what i have to do if i want to add "move up" and "move down" button in first form with dynamic rows?

                Comment

                Working...