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.
|
|
|
|
|
![]() |
||
javascript add / remove row problem
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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> |
|
|
|
|||
|
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
|
![]() |
| Thread Tools | |
|
|
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 |