473,800 Members | 2,725 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 2893
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 2000, using an SqlConnection object to open the database and an SqlCommand object to transfer my SQL text to the database. Is this the "dynamic SQL" that is such a bad thing? What is my alternative? Wait until after my program is working and...
1
17682
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
7
1893
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. thank you.
2
2947
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 sub-report will capture what grades the student has achieved in a list of different subjects and the reason I need it to be dynamic is that students take different subjects. Basically I've been trying to doctor the KB article on dynamic
2
6361
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 3 ways to do this: 1. Write a script to create a semi-dynamic CSS file, which will be run whenever we need to make changes to the ASP variables controlling the
7
8224
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
2986
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 got the core of the javascript from here: http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm I noticed in the demo that sometimes the content takes a long
1
4663
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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3502
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- 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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
2
5037
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 is this, I have a page which uses multiple postbacks to generate a list of dynamic text boxes with appropriate labels. However, when I do the final postback to enter the values in the dynamic textboxes into the database the values seem to become...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.