473,499 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic row with text box

45 New Member
Hi,

I have created dynamic row with text box i.e. initialy i have only one text box and add button when i clicked on add button it create another text box. and i want to append the values of dynamic text box in hidden field but its not working properly
when i am appending the values of text box it appends again and again same value mean suppose in 1st text box the value is 1 and in second the value is 2 and so on... then when i am trying to append the values in hidden field it store like this 1,1,2,1,2,3 and so on.. and i want to append only last three value if i have three text box.like 1,2,3...

Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript" type="text/javascript">
  2.      function addRow()
  3.      {
  4.           var tbl = document.getElementById('mySampleTable');
  5.           var lastRow = tbl.rows.length;
  6.           var iteration = lastRow;
  7.           var row = tbl.insertRow(lastRow);
  8.           var cellLeft = row.insertCell(0);
  9.           var textNode = document.createTextNode(iteration);
  10.           cellLeft.appendChild(textNode);
  11.           var cellRight = row.insertCell(1);
  12.           var el = document.createElement('input');
  13.           el.type = 'text';
  14.           el.name = 'txtRow' + iteration;
  15.           el.id = 'txtRow' + iteration;
  16.           //alert(el.id);
  17.           el.size = 40;
  18.           cellRight.appendChild(el);
  19.           test(lastRow);
  20.           var cellRightSel = row.insertCell(2);
  21.           var sel = document.createElement('select');
  22.           sel.name = 'selRow' + iteration;
  23.           sel.options[0] = new Option('0', '0');
  24.           sel.options[1] = new Option('1', '1');
  25.           sel.options[2] = new Option('2', '2');
  26.            sel.options[3] = new Option('3', '3');
  27.             sel.options[4] = new Option('4', '4');
  28.              sel.options[5] = new Option('5', '5');
  29.           cellRightSel.appendChild(sel);
  30.  
  31.  
  32.      }
  33.  
  34.      function removeRow()
  35.      {
  36.           var tbl = document.getElementById('mySampleTable');
  37.           var lastRow = tbl.rows.length;
  38.           if (lastRow > 2) tbl.deleteRow(lastRow - 1);
  39.      }
  40.  
  41. function test(lastRow)
  42. {
  43.  for(var i=1;i<lastRow;i++)
  44.   {
  45.         var tname= String('txtRow' + i);
  46.         document.getElementById('item').value=document.getElementById('item').value + ',' + document.getElementById(tname).value;
  47.   }
  48.   document.getElementById('item').value='';
  49. }
  50.  
  51. </script>
  52.  
  53. <tr>
  54.                                         <td>
  55.                                              1
  56.                                         </td>
  57.                                         <td>
  58.                                              <input type="text" name="txtRow1" id="txtRow1" size="40" /><input type="text" name="item" id="item" size="40" /></td>
  59.                                         <td>
  60.                                              <select name="selRow" id="selRow">
  61.                                                   <option value="0">0</option>
  62.                                                   <option value="1">1</option>
  63.                                                   <option value="2">2</option>
  64.                                                   <option value="3">3</option>
  65.                                                   <option value="4">4</option>
  66.                                                   <option value="5">5</option>
  67.                                              </select>
  68.                                         </td>
  69.                                    </tr>
  70.  
Mar 13 '09 #1
3 2878
acoder
16,027 Recognized Expert Moderator MVP
Rather than appending values to the item field, reset it to the new values, but not in the loop. Create a new variable to store the values and set the item field value to that variable value outside the loop.
Mar 13 '09 #2
tokcy
45 New Member
i have done this and its working fine but there is a problem with removing the value on click of remove button from text field i dont have any idea about this could you please to help me out!
Mar 13 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
If you run test() again when you remove a row, it should work as long as you pass the correct lastrow number.
Mar 13 '09 #4

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

Similar topics

1
2390
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
1
17626
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
7
1879
by: Abraham Luna | last post by:
how do i stop the dynamic validators from breaking explorer if i use a dynamic validator and move to a different control it breaks explorer and i can type in the page when i'm not supposed to....
2
2923
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
2
6340
by: JWL | last post by:
Hi I need to create a bunch of sites with slightly dynamic CSS. Basically, all the image paths in the CSS need to be dynamic, depending on the values of certain ASP variables. I can think of...
7
8203
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
9
2919
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...
1
4635
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
3465
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
2
5004
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
0
7012
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...
0
7225
jinu1996
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...
0
7392
tracyyun
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...
0
5479
agi2029
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,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.