inserting new html table row using Javascript?

Discussion in 'ASP .Net' started by Karim, Dec 11, 2003.

  1. Karim

    Karim Guest

    I have a form built into an html table. One of the form elements is an
    asp.net dropdownlist. For some options in the listbox, I want to insert a
    new table row under the listbox to grab some more info for that option. For
    example if someone chooses 'other', a user needs to type what other is.
    Because more than one option needs more info, I do not want to have a
    textbox for each of these options so as not to crowd the page but instead,
    dynamically insert a new textbox if one of these options are chosen.

    I also prefer to do this through clientside Javascript instead of a
    roundtrip post.
    Anyone has an example of Javascript to do this effect?
    Tnanks.

    Karim
     
    Karim, Dec 11, 2003
    #1
    1. Advertising

  2. Karim,

    Hopefully this will help.

    Regards

    Donald

    //Get reference to table.
    var Table = document.getElementById('ForecastEditor_tblForecasts');

    //Get reference to table body.
    var TableBody = Table.firstChild;

    //Create the new elements
    var NewRow = document.createElement("tr");
    var ActionsCell = document.createElement("td");
    var StartDateCell = document.createElement("td");
    var StartDateTextbox = document.createElement("input");
    var EndDateCell = document.createElement("td");
    var EndDateTextbox = document.createElement("input");
    var ValueCell = document.createElement("td");
    var ValueTextbox = document.createElement("input");

    //Add textboxes to cells
    StartDateCell.appendChild(StartDateTextbox);
    EndDateCell.appendChild(EndDateTextbox);
    ValueCell.appendChild(ValueTextbox);

    //Add elements to row.
    NewRow.appendChild(ActionsCell);
    NewRow.appendChild(StartDateCell);
    NewRow.appendChild(EndDateCell);
    NewRow.appendChild(ValueCell);

    //Add row to table
    TableBody.appendChild(NewRow);

    "Karim" <karim3411@!!yahoo!!.com> wrote in message
    news:1idrz1qrzc7fc$...
    >
    > I have a form built into an html table. One of the form elements is an
    > asp.net dropdownlist. For some options in the listbox, I want to insert a
    > new table row under the listbox to grab some more info for that option.

    For
    > example if someone chooses 'other', a user needs to type what other is.
    > Because more than one option needs more info, I do not want to have a
    > textbox for each of these options so as not to crowd the page but instead,
    > dynamically insert a new textbox if one of these options are chosen.
    >
    > I also prefer to do this through clientside Javascript instead of a
    > roundtrip post.
    > Anyone has an example of Javascript to do this effect?
    > Tnanks.
    >
    > Karim
     
    Donald Simpson, Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. phl
    Replies:
    1
    Views:
    4,438
    Martin Jay
    Jun 8, 2006
  2. rcoco

    Inserting a new row.

    rcoco, Feb 28, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    403
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Mar 1, 2007
  3. ORACLEJDEV
    Replies:
    0
    Views:
    379
    ORACLEJDEV
    Sep 11, 2008
  4. SoftLion
    Replies:
    0
    Views:
    102
    SoftLion
    May 24, 2004
  5. D
    Replies:
    0
    Views:
    257
Loading...

Share This Page