473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

dynamic table using javascript

45
hi everyone,

i am creating dynamic row in a table using javascript its working fine and now i want to create more than 1 table using javascript which is dynamic its also working fine but when i am taking the value of each table individually thats i am not able to get any value. if i get the value of table then its not taking properly.

let me explain the whole scenario...

i want to add product specification . it may vary in number of specification.i.e. i may be 2 or 10 or 30 etc.for each specification i have to add properties it is possible only using dynamic rows.like suppose if i have 5 specification and i have to add properties for each specification then i will use dynamic row creation. And now i am able to do this till now after that i am not able to take the value of all the text fields in a single text field by comma(,) separated.

how will i do this please help me out its urgent...
Apr 8 '09 #1
3 4834
acoder
16,027 Expert Mod 8TB
Please post your code, so we can see where the problem might lie.
Apr 8 '09 #2
tokcy
45
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.      <head>
  4.           <title>Dymanic Row</title>
  5. <script language="Javascript" type="text/javascript">
  6.      function addRow(str)
  7.      {
  8.           var tbl = document.getElementById('mySampleTable'+str);
  9.           var lastRow = tbl.rows.length;
  10.           var iteration = lastRow;
  11.           var row = tbl.insertRow(lastRow);
  12.           var cellLeft = row.insertCell(0);
  13.           var textNode = document.createTextNode(iteration);
  14.           //cellLeft.appendChild(textNode);
  15.           var cellRight = row.insertCell(1);
  16.           var el = document.createElement('input');
  17.           el.type = 'text';
  18.           el.name = 'txtRow' + iteration;
  19.           el.id = 'txtRow' + iteration;
  20.           el.size = 40;
  21.           cellRight.appendChild(el);
  22.           //el.setAttribute("onBlur","setvalue(this);");
  23.      }
  24.  
  25.      function removeRow(str1)
  26.      {
  27.           var tbl = document.getElementById('mySampleTable'+str1);
  28.           var lastRow = tbl.rows.length;
  29.           if (lastRow > 2) tbl.deleteRow(lastRow - 1);
  30.      }
  31.  
  32. function setvalue(str2)
  33. {
  34.     alert(str2);
  35.     var i=0;
  36.     var idstr="txtRow" + str2;
  37.     //alert('item' + str2);
  38.     document.getElementById('item' + str2).value="";
  39.     while(document.getElementById(idstr))
  40.     {
  41.     document.getElementById('item' + str2).value=document.getElementById('item' + str2).value + ',' + document.getElementById(idstr).value;
  42.     idstr='txtRow' + str2;
  43.     str2++;
  44.     }
  45. }
  46. </script>
  47.      </head>
  48.      <body leftmargin="0" topmargin="0">
  49.           <form action="#" name="frm" method="post">
  50.               <? 
  51.               $i=1;
  52.               for($i=1;$i<=5;$i++)
  53.                 {
  54.               ?>
  55.                <table align="center" width = "75%">
  56.                      <tr>
  57.                        <td align = "center">
  58.                  <input type="text" name="item<?=$i?>" id="item<?=$i?>" value="<?=$i?>" size="40" />
  59.                  <table border="1" id="mySampleTable<?=$i?>">
  60.                                      <tr>
  61.                                         <td>&nbsp;</td>
  62.                                         <td>
  63.                                              Specification
  64.                                         </td>
  65.                                         <td>&nbsp;</td>
  66.                                    </tr>
  67.  
  68.                                    <tr>
  69.                                         <td>&nbsp;</td>
  70.                                         <td>
  71.                                              <input type="text" name="txtRow<?=$i?>" id="txtRow<?=$i?>" size="40" value="<?=$i?>" onBlur="setvalue(this);" /></td>
  72.                                         <td>&nbsp;</td>
  73.                                    </tr>
  74.                               </table>
  75.                               <input type="button" name="add" id="add" value="Add" onClick="addRow('<?=$i?>'); setvalue(<?=$i?>);" />
  76.                               <input type="button" value="Remove" onClick="removeRow('<?=$i?>');" />
  77.                               <input type="submit" value="Submit" onClick="setvalue(<?=$i?>);" />
  78.                          </td>
  79.                     </tr>
  80.                </table>
  81.                <?
  82.                }
  83.                ?>
  84.           </form>
  85.      </body>
  86. </html>
  87.  
Apr 8 '09 #3
acoder
16,027 Expert Mod 8TB
You're passing 'this' to setvalue when you probably mean to pass a string.
Apr 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Travis Pupkin | last post by:
Hey, I've done a number of product catalogs/galleries with one or two category levels (Category > Subcategory). The straightforward way to do this, of course, is to use database fields for...
1
by: OM | last post by:
I am trying to present tree-structure information using a html table and JavaScript. Each tree node is displayed in the first column in a table row. The tree node can also have additional...
18
by: chimalus | last post by:
I am using a table with no column widths specified, letting the table layout manager do its thing for figuring out the column widths, and this works just fine. Now I want to make the table...
1
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
2
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.