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



Home Answers Viewqa Ajax Javascript & AJAX query
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Venu
Javascript & AJAX query
2 Answer(s)      5 years and 10 months ago
Posted in : Ajax



Advertisement
View Answers

January 15, 2009 at 12:13 AM


Hi friend,

Code to help in solving the problem and follow some points :

Step 1: Create a web page ("addperson.jsp") to add and remove the person.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Add/Delete Person</TITLE>
<script>
function validate()
{

var len;
if(document.getElementById("psize").value=="")
{
len = 1;
}
else
{
len = parseInt(document.getElementById("psize").value);
}

for(var i=1; i<=len; i++) {
var person = "person" + i;
if(document.getElementById(person).value=="")
{
alert("Please enter person");
document.getElementById(person).focus();
return false;
}
}
return true;
}
function addRow()
{
var ptable = document.getElementById('ptablePerson');
var lastElement = ptable.rows.length;
var index = lastElement;
var row = ptable.insertRow(lastElement);


var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(index);
cellLeft.appendChild(textNode);

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

cellText.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>
</HEAD>

<BODY>

<form action="show.jsp" method="post" onsubmit="return validate();">
<input type="hidden" name="psize" id="psize">
<table style="border:1px solid #000000;" bgcolor="#efefef"
id="ptablePerson" align="center">

<tr>
<th colspan="3">Add New Person</th>
</tr>
<tr>
<td>1</td>
<td><input type="text" name="person1" id="person1" size="30" />

<input type="button" value="Add" onclick="addRow();" /></td>

</tr>
</table>
<table align="center">
<tr><td><input type="button" value="Remove" onclick="removeRow();" />

<input type="Submit" value="Submit" /></td></tr>
</table>
</form>
</BODY>
</HTML>


January 15, 2009 at 1:18 AM


Step:2Create a webpage ("show .jsp") to display the person.

<html>
<body>
<br><br>
<table width="200px" align="center" style="border:1px solid #000000;">
<tr><th>Person List</th></tr>
<%
String person ="";
int size=0;
if(request.getParameter("psize")!=null && request.getParameter("psize")!="")
{
try
{
size = Integer.parseInt(request.getParameter("psize").toString());
//out.println(size);
for(int i=1;i<=size;i++)
{
person = "person"+i;
%>
<tr><td style="background-color:#f7f7f7;color:green;font-weight:bold;text-align:center;">

<%=request.getParameter(person).toString()%></td></tr>
<%
}
}
catch(Exception e)
{
out.println("Error1 : " + e.getMessage());
}

}
else if(request.getParameter("person1")!=null && request.getParameter("person1")!="")
{

try
{
%>
<tr><td style="background-color:#efefef;color:#ff0000;font-weight:bold;text-align:center;">

<%=request.getParameter("person1").toString()%></td></tr>
<%
}
catch(Exception e)
{
out.println("Error2 : " +e.getMessage());
}


}
else
{
%>
<tr><td><%="No Person Found"%></td></tr>
<%
}


%>
</table>
</html>

Thanks


Related Tutorials/Questions & Answers:
Javascript & AJAX query - Ajax
Javascript & AJAX query  Hi This is Venu.I want the coding for javascript i.e when i select a radio button it should display a text box along with a button(suppose name the button name as Addmore).When i click
javascript query
javascript query  how to get javascript variable value into java variable?? i have one value in javascript variable(var name = value ) i want this name variable value in java variable (string name1
Advertisements
javascript - Ajax
click on particular image of slide show in javascript. i used href tag but it does not work so i m posting my javascript code here below. note: in the head
Query on java - Ajax
Query on java  what is modal form
query related to roseindia example - Ajax
query related to roseindia example  http://www.roseindia.net/ajax/File-Upload.shtml In FileUploadServlet.java where is "fileupload package" I am getting error on "import org.apache.commons.fileupload.disk.DiskFileItemFactory
Dojo/Javascript - Ajax
Dojo/Javascript  Dojo/Javascript question: I get a message that ?dijit.byId is not a function? when debugging in firebug. I usually see dijit.byId embedded in an assignment (e.g. dijit.byId(?myId?).getValue();). So I don
database call from javaScript - Ajax
database call from javaScript  Dear All, In my project i have one... name. and i have to do this in javascript.How do i call database query ,if suppose i have selected two building from text area,i have to finish
javascript drag drop treeview - Ajax
javascript drag drop treeview  Hello Friends, I want to create javascript treeview which display folders and files from actual location of client... what i need is not just click drag script. I want to create Javascript which
how to done calculation for dynamic generated textboxes in jquery/javascript/ajax?
how to done calculation for dynamic generated textboxes in jquery/javascript/ajax?  how to done calculation for dynamic generated textboxes in jquery/javascript/ajax
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I....), how to manipulate date validations through JavaScript or Ajax? Thanks in Advance, Sreenivasulu Arveti.   Hi, You can write normal JavaScript
Urgent query about CreateTextFile using Javascript
Urgent query about CreateTextFile using Javascript  Dear All, I am creating a file using the code below which create a text file, but I don't want any body to access the same, either it should be password protected or it should
Sigma grid -- Ajax-enabled JavaScript grid
Sigma grid -- Ajax-enabled JavaScript grid       Sigma Grid Sigma Grid is a freely open source AJAX editable data grid, written in pure javascript for displaying and inline
How can I get query string values in JavaScript?
How can I get query string values in JavaScript?  How can I get query string values in JavaScript?   To get a query string value, you can use JQuery and JavaScript.. here is the code: function getParameterByName(name
Ajax Resources
; Web 2.0 Technologies Blog with resources for AJAX, javaScript and rails... ajax, css, dhtml, xml, javascript, and geekier   AJAX Goals AJAX... This is a JavaScript class that makes using AJAX really, REALLY simple and robust
start date and end date validation in javascript - Ajax
start date and end date validation in javascript  hi, i am doing web surfing project. pls guide me for my project. i want start date and end validations in javascript. end date should be greater than start date if so less than
Ajax
Ajax  Hi, What is Ajax? What is the use of Ajax? Thanks   Hi, Ajax is set of technologies used to develop dynamic web applications. In Ajax following technologies is used: a) JavaScript b) XML c) HTTP d) CSS Learn
Ajax - Asynchronous JavaScript and XML, What is Ajax?
What is Ajax - Asynchronous JavaScript and XML   ... become extremely popular these days. What is Ajax? Asynchronous JavaScript and XML... application   Ajax is easy to learn. Ajax is based on JavaScript
how to use javascript drag and drop files upload - Ajax
how to use javascript drag and drop files upload  Hi,Sir Please, I would like to upload multiple files using javascript with drag and drop style.I... javascript drag and drop code for this problem. I have no reference code
Ask Ajax Questions Online
Ask Ajax Questions Online       AJAX refers to Asynchronous JavaScript and XML, an amalgamation of JavaScript and XML used for creating interactive web
Ajax
Ajax  How to learn AJAX
ajax
ajax  please describe the ajax
AJAX - Ajax
: Asynchronous JavaScript and XML or Ajax for short is new web development technique used... * Ajax is easy to learn. Ajax is based on JavaScript and existing...AJAX  what is Ajax?WHAT IS THE USAGE OF IT?WHERE WE HAVE TO USE
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title> <script language="Javascript"> function postRequest(strURL) { var
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title> <script language="Javascript"> function postRequest(strURL) { var
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title> <script language="Javascript"> function postRequest(strURL) { var
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title> <script language="Javascript"> function postRequest(strURL) { var
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
AJAX - Ajax
. Ajax sometimes also called the blend of Asynchronous JavaScript and XML is a speedy...AJAX  What is AJAX?how we will use it in java?what is the use of AJAX?give me example?   hi friend, Ajax plays a major role
The AJAX JSP Tag Library
of Asynchronous JavaScript and XML (AJAX) technology in JavaServer Pages. This tag... JavaScript to implement an AJAX-capable web form. Read full Description... The AJAX JSP Tag Library      
 

 

 

DMCA.com