Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process Multiarray concept
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


pragalathan
Multiarray concept
3 Answer(s)      4 years and a month ago
Posted in : Development process


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


Advertisement
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
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
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
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
Explain the concept of thread priorities in Java.
Explain the concept of thread priorities in Java.  Explain the concept of thread priorities in Java
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
Write Full concept of abstract class
Write Full concept of abstract class  Abstract class
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
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
Does javaScript have the concept level scope?
Does javaScript have the concept level scope?  Does javaScript have the concept level scope
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
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
 

 

 

DMCA.com