how to dynamically add a row for each click on a link

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prathna
    New Member
    • Jun 2007
    • 7

    how to dynamically add a row for each click on a link

    hi all..
    Im new to DHTMl,Javascrip t

    I have 4 rows each with a dropdownlist,te xtfield.I have a link.When the user clicks a link first time.i show one row now based what i select in the dropdownlist i want to show the corresponding row...now my issue is how can i change the position of where the row should appear.say in html i have rows of id1 ,id2,id3.By default it would show in the same order is it possible to change the place where it is displayed .that is can i dynamically display a row in the first line the 1st time & make it display it in another line next time based on the values..


    I have been trying to do this.I need it ver badly..If someone could help it would be really great

    Thanks in Advance
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Originally posted by prathna
    hi all..
    Im new to DHTMl,Javascrip t

    I have 4 rows each with a dropdownlist,te xtfield.I have a link.When the user clicks a link first time.i show one row now based what i select in the dropdownlist i want to show the corresponding row...now my issue is how can i change the position of where the row should appear.say in html i have rows of id1 ,id2,id3.By default it would show in the same order is it possible to change the place where it is displayed .that is can i dynamically display a row in the first line the 1st time & make it display it in another line next time based on the values..


    I have been trying to do this.I need it ver badly..If someone could help it would be really great

    Thanks in Advance
    i have a difficulty understanding what you're trying to do. All i know is that you have 4 rows and they should be displayed dynamically. the rest is blurry.

    Please re explain or provide some code.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      hi ...

      may be the following simple example is of help to you. i think you want to add the rows to a table in the same order as the options in a select-element are selected? otherwise explain your problem in more detail and/or post the code you already have.

      [HTML]<html>
      <head>
      <script type="text/javascript">
      var opts_rows = {};

      function create_lines() {
      var opts = document.getEle mentById('my_op tions');

      for (var i = 0, opt; opt = opts[i]; i++) {
      var row = document.create Element('td');
      row.innerHTML = '<td>row for option: ' + opt.value + '</td>';

      opts_rows[opt.value] = row;
      }
      }

      function add_line(node) {
      var cnt = document.getEle mentById('my_ta ble');
      var tgt = cnt.getElements ByTagName('tbod y')[0];

      tgt.appendChild (opts_rows[node.value]);
      }
      </script>
      </head>
      <body onload="create_ lines();">
      <select id="my_options " onchange="add_l ine(this);">
      <option value="0">selec t an option</option>
      <option value="1">optio n 1</option>
      <option value="2">optio n 2</option>
      <option value="3">optio n 3</option>
      </select>
      <table id="my_table">< tbody></tbody></table>
      </body>
      </html>
      [/HTML]
      kind regards

      Comment

      • prathna
        New Member
        • Jun 2007
        • 7

        #4
        how to dynamically add a row for each click on a link

        Hi,
        I have a row with a dropdownlist and textfield .
        now i have a link called 'add'.
        I would like to know how to add a row dynamically for each click on the link using jsp & javascript.
        In short each time i click add link i want a row with dropdownlist and textfield.
        and also these values have to be set in the formbean.

        I have no idea how to do add a row dynamically & also set it to the formbean dynamucally.It would be really great if someone could provide me with a sample code with a simple example.

        Thanks in Advance

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          see this example...

          The W3Schools online code editor allows you to edit code and view the result in your browser

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            I've merged the two threads because they seem to relate to the same problem. Please keep it to one thread. Thanks!

            Comment

            • prathna
              New Member
              • Jun 2007
              • 7

              #7
              thanks for the example help is much appreciated .

              Comment

              Working...