By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

inserting new html table row using Javascript?

P: n/a

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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Karim,

Hopefully this will help.

Regards

Donald

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

//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:1i******************************@40tude.net.. .

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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.