473,387 Members | 1,528 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,387 software developers and data experts.

add input textbox between field in a form

123 100+
My code below, I can add and remove textbox, however, it can add/remove the
last one only.

How I can add a input textbox between field?

thanks.

my html file
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="addHTMLControls.js"></script>
  2. <a href="javascript:addInput()">Add more input field(s)</a><br>
  3. <a href="javascript:deleteInput()">Remove field(s)</a>
my .js file
Expand|Select|Wrap|Line Numbers
  1. var arrInput = new Array(0);
  2.   var arrInputValue = new Array(0);
  3.  
  4. function addInput() {
  5.   arrInput.push(arrInput.length);
  6.   arrInputValue.push("");
  7.   display();
  8. }
  9.  
  10. function display() {
  11.   document.getElementById('parah').innerHTML="";
  12.   for (intI=0;intI<arrInput.length;intI++) {
  13.     document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  14.   }
  15. }
  16.  
  17. function saveValue(intId,strValue) {
  18.   arrInputValue[intId]=strValue;
  19. }  
  20.  
  21. function createInput(id,value) {
  22.   return "<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>";
  23. }
  24.  
  25. function deleteInput() {
  26.   if (arrInput.length > 0) { 
  27.      arrInput.pop(); 
  28.      arrInputValue.pop();
  29.   }
  30.   display(); 
  31. }
Nov 20 '08 #1
2 3494
RamananKalirajan
608 512MB
Hi, it seems to be u are maintaining a stack inorder to add or remove the input text field in the form. Can u please explain what u are trying to do. Do You want to add the field randomly inside the form

Regards
Ramanan Kalirajan
Nov 20 '08 #2
acoder
16,027 Expert Mod 8TB
My code below, I can add and remove textbox, however, it can add/remove the
last one only.

How I can add a input textbox between field?
The code is horribly inefficient in that it recreates everything again. Surely, it'd be better to only add/delete what you need. It would, however, require more or less a complete rewrite. Are you prepared to do that?

The main problems are the push/pop - they only affect the last array item. You need to use the index of the array to affect other items or use splice() to add items.
Nov 20 '08 #3

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

Similar topics

4
by: Agnes | last post by:
I use while-loop the show the table content in web page. e.g (bookingno, booking date,customer no) However, the client need me insert one column (confirmdate ) and allow the user input and update...
4
by: Roger Withnell | last post by:
I want to validate the data entered into a form text field by calling a function with onblur, doing the validation and, if the input is invalid, giving an alert to the user and returning focus and...
2
by: johnp | last post by:
Hi, Our Tech department updated users to Office 2003 this week. Now the input mask in one of the applications is showing up as: (###) ###-### The input mask wizard works correctly when I...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
2
by: Robert Bravery | last post by:
HI all, I have a form for searches on a mysql database/table. The form has on input text box, and several pushbuttons. Depending on which pushbutton is selected, the search is then done on a...
5
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
9
by: keydrive | last post by:
There must be a difference between a standard input field and a textbox field. I would like to use a textbox field and save the value in a hidden field for paging. This works in a default input...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
5
by: Dave Rado | last post by:
Hi I have been the following code by Freefind to use on my search page: <form action="http://search.freefind.com/find.html" method="get" accept-charset="utf-8" target="_self"> <input...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.