Please help me to adding multiple row at a time... - // Last updated 2006-02-21
-
-
<script language="javascript">
-
function addRowToTable()
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length;
-
// if there's no header row in the table, then iteration = lastRow + 1
-
var iteration = lastRow;
-
var row = tbl.insertRow(lastRow);
-
-
// left cell
-
var cellLeft = row.insertCell(0);
-
var textNode = document.createTextNode(iteration);
-
cellLeft.appendChild(textNode);
-
-
// right cell
-
var cellRight = row.insertCell(1);
-
var el = document.createElement('input');
-
el.type = 'text';
-
el.name = 'txtRow' + iteration;
-
el.id = 'txtRow' + iteration;
-
el.size = 40;
-
-
el.onkeypress = keyPressTest;
-
cellRight.appendChild(el);
-
-
// select cell
-
var cellRightSel = row.insertCell(2);
-
var sel = document.createElement('select');
-
sel.name = 'selRow' + iteration;
-
sel.options[0] = new Option('text zero', 'value0');
-
sel.options[1] = new Option('text one', 'value1');
-
cellRightSel.appendChild(sel);
-
}
-
-
-
function keyPressTest(e, obj)
-
{
-
var validateChkb = document.getElementById('chkValidateOnKeyPress');
-
if (validateChkb.checked) {
-
var displayObj = document.getElementById('spanOutput');
-
var key;
-
if(window.event) {
-
key = window.event.keyCode;
-
}
-
else if(e.which) {
-
key = e.which;
-
}
-
var objId;
-
if (obj != null) {
-
objId = obj.id;
-
} else {
-
objId = this.id;
-
}
-
displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
-
}
-
}
-
-
-
-
function removeRowFromTable()
-
{
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length;
-
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
-
}
-
-
-
-
function openInNewWindow(frm)
-
{
-
// open a blank window
-
var aWindow = window.open('', 'TableAddRowNewWindow',
-
'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
-
-
// set the target to the blank window
-
frm.target = 'TableAddRowNewWindow';
-
-
// submit
-
frm.submit();
-
}
-
-
-
-
function validateRow(frm)
-
{
-
var chkb = document.getElementById('chkValidate');
-
if (chkb.checked) {
-
var tbl = document.getElementById('tblSample');
-
var lastRow = tbl.rows.length - 1;
-
var i;
-
for (i=1; i<=lastRow; i++) {
-
var aRow = document.getElementById('txtRow' + i);
-
if (aRow.value.length <= 0) {
-
alert('Row ' + i + ' is empty');
-
return;
-
}
-
}
-
}
-
openInNewWindow(frm);
-
}
-
</script>
-
-
<form action="tableaddrow_nw.html" method="get">
-
<p>
-
<input type="button" value="Add" onclick="addRowToTable();" />
-
<input type="button" value="Remove" onclick="removeRowFromTable();" />
-
<input type="button" value="Submit" onclick="validateRow(this.form);" />
-
<input type="checkbox" id="chkValidate" /> Validate Submit
-
</p>
-
<p>
-
<input type="checkbox" id="chkValidateOnKeyPress" checked="checked" /> Display OnKeyPress
-
<span id="spanOutput" style="border: 1px solid #000; padding: 3px;"> </span>
-
</p>
-
<table border="1" id="tblSample">
-
<table border="1" id="referfs">
-
<tr>
-
<tr>
-
<td> 1.</td>
-
<td size = "30">Salutation</td>
-
<td>:</td>
-
<td>
-
<select name="selRow0">
-
<option value="value0">Mr</option>
-
<option value="value1">Ms</option>
-
<option value="value1">Madam</option>
-
</select>
-
</td>
-
</tr>
-
-
<tr>
-
<td> </td>
-
<td size = "30">Friend's Name</td>
-
<td>:</td>
-
<td><input type="text" name="txtRow1" id="txtRow1" size="20" onkeypress="keyPressTest(event, this);" /></td>
-
</tr>
-
-
<tr>
-
<td> </td>
-
<td size = "30">Friend's Email</td>
-
<td>:</td>
-
<td><input type="text" name="txtRow1" id="txtRow1" size="20" onkeypress="keyPressTest(event, this);" /></td>
-
</tr>
-
-
<tr>
-
<td> </td>
-
<td size = "30">Friend's Phone Number</td>
-
<td>:</td>
-
<td><input type="text" name="txtRow1" id="txtRow1" size="20" onkeypress="keyPressTest(event, this);" /></td>
-
</tr>
-
</tr>
-
</table>
-
</table>
-
</form>
Hope anybody can help me to finish this code..:(
3 4912 acoder 16,027
Recognized Expert Moderator MVP
By multiple, do you mean a fixed number, e.g. 2, or a number that you want to allow the user to decide?
if u try run tis code and u click add button..only the last row will added..
In my case, I want row start from "Salutation" till row phone number will repeat..means that when click add button, 4 row will added..
thanks..:)
acoder 16,027
Recognized Expert Moderator MVP
Just extend the code in addRowToTable(). Which part of that code do you not understand?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DotNetJunky |
last post by:
I have built a control that runs an on-line help system. Depending on the
category you selected via dropdownlist, it goes out and gets the child
subcategories, and if there are any, adds a new...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that...
|
by: Andrew |
last post by:
Hey all,
I am very new to ASP.Net (and .Net in general), but that isn't stopping the
boss from wanting to begin new projects in it. This latest project has me
kinda stumped and after a couple...
|
by: Sileesh |
last post by:
Hi
I have html table and a Button in an Aspx page. I am adding one row with
some textboxes to Html table each time i click on the Button thru Javascript.
Now problem is when when i try to...
|
by: Bob Hollness |
last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the
questions I may ask!
I have a datagrid which I have populated from a database. It works great!
I have added a column, via...
| |
by: Amy |
last post by:
Is it possible to do so?
|
by: EricLondaits |
last post by:
Hi,
I have an ASP.NET page with a ListBox that is data bound to a table
with a single field (it holds a list of valid IDs). The page also has
a textBox into which you can add new valid IDs, one...
|
by: mdfayazi |
last post by:
I am using dataadapter to Add,Update,Delete rows in a datagridview.Update and delete are working but while adding a rows the problem comes.When I add more than one row only first row values are...
|
by: Lewis Holmes |
last post by:
Hi
I have the following situation in one of my asp.net pages.
The user can add multiple table rows to a form by selecting a button. These
rows can contain asp.net controls. When this button is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |