javascript add / remove row problem

This is a discussion on "javascript add / remove row problem" within the JavaScript Forum section. This forum, and the thread "javascript add / remove row problem are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 25th, 2008, 00:38
New Member
Join Date: Jan 2008
Location: sydney
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
javascript add / remove row problem

Hi everyone,

I currently have this script on my page that allows users to add and remove rows in the page. I have a another script that calculates a value on the dynamically generated elements and static ones too.

my problem is, I cant figure out a way to pass in a value for the inputs variable and have it as the base for the row generation...

My question is... how do i pass in a value for the function to begin its creation of the rows.. ? as i have multiple tables with different IDs scattered through my page...

any help greatly appreciated.

ta

<script language="javascript">

var inputs = 4 ;

function addContact(AreaName,AttName1,AttName2)
{

var table = document.getElementById(AreaName);

var tr = document.createElement('TR');
var td1 = document.createElement('TD');
td1.setAttribute("width","250");

var td2 = document.createElement('TD');
td2.setAttribute("width","110");
td2.setAttribute("align","center");

var td3 = document.createElement('TD');
td2.setAttribute("width","110");
td3.setAttribute("align","center");

var td4 = document.createElement('TD');

var inp1 = document.createElement('INPUT');
var inp2 = document.createElement('INPUT');
var inp3 = document.createElement('INPUT');


if(inputs>=0)
{
var img = document.createElement('IMG');
img.setAttribute('src', 'images/p6_delete.gif');
img.onclick = function(){
removeContact(tr);
}

// var img2 = document.createElement('IMG');
// img2.setAttribute('src', 'images/other.gif');

td1.appendChild(img);
// td1.appendChild(img2);


var img3 = document.createElement('IMG');
img3.setAttribute('src', 'images/percent.gif');
img3.setAttribute('height','13');
img3.setAttribute('width','13');

td2.appendChild(img3);

var img4 = document.createElement('IMG');
img4.setAttribute('src', 'images/dollar.gif');
img4.setAttribute('height','13');
img4.setAttribute('width','13');

td3.appendChild(img4);

}

inp1.setAttribute("Name", AttName1 + inputs);
inp1.setAttribute("class","required");
inp1.setAttribute("id", AttName1 + inputs);
inp1.setAttribute("size","2");
inp1.setAttribute("style","width:35px;");

inp2.setAttribute("Name", AttName2 + inputs);
inp2.setAttribute("class","required");
inp2.setAttribute("id", AttName2 + inputs);
inp2.setAttribute("size","2");
inp2.setAttribute("style","width:40px;");

inp3.setAttribute("Name","Other" + AttName2 + inputs);
inp3.setAttribute("class","required");
inp3.setAttribute("id", "Other" + AttName2 + inputs);
inp3.setAttribute("style","width:170px;");
inp3.setAttribute("title","title for the element");

table.appendChild(tr);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);

td1.appendChild(inp3);
td2.appendChild(inp2);
td3.appendChild(inp1);

inputs++;

}

function removeContact(tr)
{
tr.parentNode.removeChild(tr);
}
</script>
Reply With Quote

  #2 (permalink)  
Old Feb 25th, 2008, 09:36
New Member
Join Date: Jan 2008
Location: sydney
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: javascript add / remove row problem

its alright i solved it my self. i made a mod to the script to count how many dynamically generated rows there are on the page and to - 1 to calculate an accurate number of form fields there were. too easy
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Javascript problem Popje JavaScript Forum 2 Jan 24th, 2008 02:51
problem with JavaScript and JSP pesho318i JavaScript Forum 0 Jan 23rd, 2008 18:04
Javascript problem zc1 JavaScript Forum 2 Jan 15th, 2007 17:01
Remove UL spacing problem relph2 Web Page Design 3 Jan 3rd, 2006 17:22
Difficult Javascript Problem! craig JavaScript Forum 7 Dec 7th, 2005 09:36


All times are GMT. The time now is 19:26.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43