Multiarray concept

Multiarray concept

i have 4 text box in html page, when i click new it would want to add another 4 like that ,i will go on like this? when i click delete last four buttons want to delete from it. how i can do this using js and php

With Regards pragal

View Answers

November 26, 2010 at 5:03 PM

Hi Friend,

Try the following code:

<html>
  <script>
function addRow(){
  var ptable = document.getElementById('ptablePerson');
  var lastElement = ptable.rows.length;
  var index = lastElement;
  var row = ptable.insertRow(lastElement);

  var cellText1 = row.insertCell(0);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText1.appendChild(element);

  var cellText2 = row.insertCell(1);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText2.appendChild(element);

  var cellText3 = row.insertCell(2);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText3.appendChild(element);

  var cellText4 = row.insertCell(3);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText4.appendChild(element);

  document.getElementById("psize").value=index;
  }
function removeRow(){
  var ptable = document.getElementById('ptablePerson');
  var lastElement = ptable.rows.length;
  if (lastElement > 2) ptable.deleteRow(lastElement - 1);
  if(document.getElementById("psize").value>1)
    {
       document.getElementById("psize").value = 
           document.getElementById("psize").value-1;
    }
}
</script>
<form >
<input type="hidden" name="psize" id="psize">
<table style="border:1px solid #000000;" bgcolor="#efefef" 
  id="ptablePerson" align="center">
<tr>
<td><input type="text" name="person1"  id="person1" size="30" /></td>
<td><input type="text" name="person1"  id="person2" size="30" /></td>
<td><input type="text" name="person1"  id="person3" size="30" /></td>
<td><input type="text" name="person1"  id="person4" size="30" /></td>
</tr>
</table>
<table align="center">
 <tr><td><input type="button" value="Add" onclick="addRow();" /></td>
 <td><input type="button" value="Remove" onclick="removeRow();" /></td></tr>
</table>
</form>
</html>

Thanks


November 26, 2010 at 5:03 PM

Hi Friend,

Try the following code:

<html>
  <script>
function addRow(){
  var ptable = document.getElementById('ptablePerson');
  var lastElement = ptable.rows.length;
  var index = lastElement;
  var row = ptable.insertRow(lastElement);

  var cellText1 = row.insertCell(0);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText1.appendChild(element);

  var cellText2 = row.insertCell(1);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText2.appendChild(element);

  var cellText3 = row.insertCell(2);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText3.appendChild(element);

  var cellText4 = row.insertCell(3);
  var element = document.createElement('input');
  element.type = 'text';
  element.name = 'person' + index;
  element.id = 'person' + index;
  element.size = 30;
  cellText4.appendChild(element);

  document.getElementById("psize").value=index;
  }
function removeRow(){
  var ptable = document.getElementById('ptablePerson');
  var lastElement = ptable.rows.length;
  if (lastElement > 2) ptable.deleteRow(lastElement - 1);
  if(document.getElementById("psize").value>1)
    {
       document.getElementById("psize").value = 
           document.getElementById("psize").value-1;
    }
}
</script>
<form >
<input type="hidden" name="psize" id="psize">
<table style="border:1px solid #000000;" bgcolor="#efefef" 
  id="ptablePerson" align="center">
<tr>
<td><input type="text" name="person1"  id="person1" size="30" /></td>
<td><input type="text" name="person1"  id="person2" size="30" /></td>
<td><input type="text" name="person1"  id="person3" size="30" /></td>
<td><input type="text" name="person1"  id="person4" size="30" /></td>
</tr>
</table>
<table align="center">
 <tr><td><input type="button" value="Add" onclick="addRow();" /></td>
 <td><input type="button" value="Remove" onclick="removeRow();" /></td></tr>
</table>
</form>
</html>

Thanks


November 30, 2010 at 6:12 PM

Hi Friend thanks to you , Your code really helps me and i want to do this with an array.

With regards, pragal









Related Tutorials/Questions & Answers:
Multiarray concept
Multiarray concept  i have 4 text box in html page, when i click new it would want to add another 4 like that ,i will go on like this? when i click delete last four buttons want to delete from it. how i can do this using js
Explain normalization concept?
Explain normalization concept?  Explain normalization concept
Advertisements
Concept of subqueires using JSP
Concept of subqueires using JSP  Can I implement the concept of sub queries in JSP page , if yes please tell me how this can be achieved. I have requirement where output of the SQL query should be given as input to the update
session concept - JSP-Servlet
session concept  Hello friends, How can we track unexpectedly closing a window when a jsp project running with session concept. And this tracking should update the log in status in data base
Session concept - JSP-Servlet
Session concept  Hai friends, I am doing a jsp project with session concept. If one person is not accessing his logged window for more than 10 minutes it gets automatically log out.Anybody explain me the reason
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
FILE HANDLING CONCEPT
FILE HANDLING CONCEPT   Write a program that reads input from the console in the form of a string. When the user enters a word called end, the program should stop reading from the console and print out the values that have been
Explain the concept of thread priorities in Java.
Explain the concept of thread priorities in Java.  Explain the concept of thread priorities in Java
Java Inheritance Concept.
Java Inheritance Concept.  Yesterday i got confused with following question in an aptitude exam. Question:Class A,B,C have method named doit(). Class B extends Class A,Class C extends Class B.How will you call method doit
Write Full concept of abstract class
Write Full concept of abstract class  Abstract class
ModuleNotFoundError: No module named 'concept-formation'
ModuleNotFoundError: No module named 'concept-formation'  Hi, My... named 'concept-formation' How to remove the ModuleNotFoundError: No module named 'concept-formation' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'concept-formation'
ModuleNotFoundError: No module named 'concept-formation'  Hi, My... named 'concept-formation' How to remove the ModuleNotFoundError: No module named 'concept-formation' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'concept-formation'
ModuleNotFoundError: No module named 'concept-formation'  Hi, My... named 'concept-formation' How to remove the ModuleNotFoundError: No module named 'concept-formation' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'concept-py'
ModuleNotFoundError: No module named 'concept-py'  Hi, My Python... 'concept-py' How to remove the ModuleNotFoundError: No module named 'concept-py' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'concept-formation'
ModuleNotFoundError: No module named 'concept-formation'  Hi, My... named 'concept-formation' How to remove the ModuleNotFoundError: No module named 'concept-formation' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'concept-py'
ModuleNotFoundError: No module named 'concept-py'  Hi, My Python... 'concept-py' How to remove the ModuleNotFoundError: No module named 'concept-py' error? Thanks   Hi, In your python environment you
Concept error - WebSevices
Concept error  What is the difference between Joomla And Zend framework. Any one know the answer  Hi friend, Joomla CMS is a multi functional Open Source application for creating websites. It is free to use
concept Understatnding problem - Java Beginners
concept Understatnding problem  Even though I have studied in detail inheritance & interfaces in java , I fail to understand "How Interfaces Help in Multiple Inheritance ?" . Pls. Supplement ur ans. with an example. Thanx
Java Query(based on swing concept)
Java Query(based on swing concept)  I want a particular submit button to get disabled whenever i write some account number starting with 774 and 775 in a text box of that screen
Does javaScript have the concept level scope?
Does javaScript have the concept level scope?  Does javaScript have the concept level scope
PHP MultiArray Sorting
Java + Timer concept - Java Beginners
concept.  Hi Friend, Try the following code: import java.awt.
Connected Mode and Dissconnect mode coding concept.
Connected Mode and Dissconnect mode coding concept.  Tell Me about Connected Mode and Dissconnect mode coding concept. also give me some syantax
how to call a frame having threading concept
how to call a frame having threading concept   i hav a frame having buttton on it .on click event of the button ,i want to call another frame which implements threading concept. i tried it simply by calling constructor
about the concept - Design concepts & design patterns
about the concept  sir,please explain me how should i interpret the concept "object oriented technology" and how it is differ from "structured langauge".  Object Oriented Language http://www.roseindia.net/java/master
OOPS Concept Abstraction with example - Java Beginners
OOPS Concept Abstraction with example  I am new to java. In java OOPS concept Abstraction means abstract or something. Please explain it with one example  Hi Friend, The process of abstraction in Java is used
IO concept
Thread concept
programming concept
serialization concept
FILE CONCEPT
oop concept
Required help about the concept of JSP page reloading
Required help about the concept of JSP page reloading  Hi, We have one application with Websphere portlet Factory generated JSP as front end, Java in the business layer and finally DB2 as back-end. In certain cases
Required help about the concept of JSP page reloading
Required help about the concept of JSP page reloading  Hi, We have one application with Websphere portlet Factory generated JSP as front end, Java in the business layer and finally DB2 as back-end. In certain cases
how to call a frame having threading concept
how to call a frame having threading concept   i hav a frame having buttton on it .on click event of the button ,i want to call another frame which implements threading concept. i tried it simply by calling constructor
ModuleNotFoundError: No module named 'tool-for-time-tracking-just-proof-of-concept'
-of-concept'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'tool-for-time-tracking-just-proof-of-concept...-tracking-just-proof-of-concept' error? Thanks   Hi, In your
wrapper class concept
FILE HANDLING CONCEPT
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT
FILE HANDLING CONCEPT
SOCKET PROGRAMING IN THE JAVA FOR NETWORKING CONCEPT
registration form using oop concept
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.  (Aim:- The main aim of this experiment...; Here is a code that demonstrates you the concept of multiple inheritance
A JDBC Connection Pooling Concept
How to Display Next question from database after clicking Next Button using "Arraylist concept"
How to Display Next question from database after clicking Next Button using "Arraylist concept"  </tr> <%if (pageName.equals("1")) {%> <tr> <td> <div style
Inheritance in Java 7
This tutorial describe concept of Inheritance. It is one of OOPs concept
Polymorphism in Java 7
This tutorial describe concept of Polymorphism. It is one of OOPs concept

Ads