Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Adding rows to tables using JavaScript
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kristabel
New Member

United Kingdom
83 Posts

Posted - 09 March 2001 :  07:24:14  Show Profile  Visit Kristabel's Homepage
Hi,

I'm looking into how to add rows to a table. The situation will be that there could be any number of designers for a company so I want to have a 'Click here to add a designer' link or button which will then add a new row to the table for them to complete the details.

I have set up a simple test page to see how this might work. This is the code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<SCRIPT language="JavaScript">
function ADD_NEW_ROW(tableName)
{
//alert("adding a new row to table " + tableName);
document.getElementsByName(tableName).insertRow;
document.getElementsByName(tableName).insertCol;
}
</SCRIPT>
<body bgcolor="#FFFFFF" text="#000000">
<table name="myTable">
<tr>
<td>TEXT</td>
<td>TEXT 2</td>
</tr>
</table>
<p> </p>
<p><a onClick="JavaScript:ADD_NEW_ROW('myTable');">Click to add a new row</a> </p>
</body>
</html>

I have found info on the web about using insertRow but it doesn't appear to be doing anything!

Does anyone have any experience of doing what I need to do?

Thanks in advance...

'Live, love and learn'

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 09 March 2001 :  17:36:31  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
why not have it load into a javascript variable, then open a new window executing an asp script with the row variables in the querystring, then have the window autoclose when its done executing?

----------------
Da_Stimulator
Need a Mod?
My Snitz Test Center
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 09 March 2001 :  17:37:25  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
sorry i just realized you were talking about html tables and not database tables :(

----------------
Da_Stimulator
Need a Mod?
My Snitz Test Center
Go to Top of Page

Kristabel
New Member

United Kingdom
83 Posts

Posted - 12 March 2001 :  04:05:46  Show Profile  Visit Kristabel's Homepage
Thanks anyway!

I've found a script on the web that does what I want and I've started to tweak it. Gotta get round a few problems with positioning but if I can get it to work it'll be just right!

Thanks for your help.

'Live, love and learn'
Go to Top of Page

Kristabel
New Member

United Kingdom
83 Posts

Posted - 12 March 2001 :  05:11:19  Show Profile  Visit Kristabel's Homepage
Just in case anyone wants to do this themselves and has the same problems I did, I thought I would post my solution.

I have a link that says 'Click here to add a designer'. It calls a function ADD_DESIGNER() which then changes the link to read 'Click here to add another designer' and adds a table row which contains text fields for data entry.

I had this script working on a test page but then it didn't work in my main document and I worked out that the reason for this was that the table you are adding rows to must have an ID, e.g. id="designerTable".

The script is shown below.

<SCRIPT language="JavaScript">
function ADD_DESIGNER()
{
var newRow;
var nameCell;
var trainingCell;
var studioCell;
var otherCell;

addDesignerLink.innerHTML = "Click here to add another designer";

newRow = designerDetailTable.insertRow();

nameCell = newRow.insertCell();
nameCell.innerHTML = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><input type="text" name="designerName"></font>';

trainingCell = newRow.insertCell();
trainingCell.innerHTML = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><input type="text" name="designerTraining"></font>';

studioCell = newRow.insertCell();
studioCell.innerHTML = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><input type="text" name="designStudioAddress"></font>';

otherCell = newRow.insertCell();
otherCell.innerHTML = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><input type="text" name="designerOtherDetails"></font>';
}

</SCRIPT>


'Live, love and learn'
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000 Version 3.4.07