Javascript & AJAX query

Javascript & AJAX query

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 - 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
Advertisements
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
Query on java - Ajax
Query on java  what is modal form
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
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
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... JavaScript validation, but change the error/information message as per your local
javascript - Ajax
javascript - Ajax
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
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
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 - Asynchronous JavaScript and XML, What is Ajax?
What is Ajax - Asynchronous JavaScript and XML   ... JavaScript and XML or Ajax for short is new web development technique used... are techniques used in the Ajax applications. JavaScript: 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
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
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
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  please describe the ajax
Ajax
Ajax  How to learn AJAX
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 DescriptionADS... The AJAX JSP Tag Library      
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
. 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
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax Technology
Ajax Technology         Ajax Technology Asynchronous JavaScript and XML or Ajax for short is a type of asynchronous programming technical to develop
Ajax
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
What is Ajax?
JavaScript and other technologies such as CSS and XML. Read more at What is Ajax...What is Ajax?  Hi, What is Ajax and what is use of Ajax in web programming? Thanks   Hi, Ajax stands for AJAX stands for Asynchronous
Ajax
Ajax  how to include ajax in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example.ADS_TO_REPLACE_1 Instead of using PHP you can write your code in JSP. Thanks
ajax
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
Ajax technology
Ajax technology  hii, What is ajax ??   hello,ADS_TO_REPLACE_1 Ajax stands for Asynchronous Javascript & XML....   Hi, Learn it at Ajax Tutorial page.ADS_TO_REPLACE_2 Regards
Ajax - Ajax
Ajax  What is Ajax ? How one can use ajax with Java
AJAX
ajax. My table is CREATE TABLE HTNEWMETER ( ID NUMBER (10) NOT NULL, METERNO.../javascript"> function showData(value){ alert("--------------"+value); xmlHttp
ajax
ajax  HI, In my application using ajax if i type a managername in the textbox it should display all the employees under the that manager... me reg this. thanks KK   Combobox box using Ajax in JSP   i
Ajax - Asynchronous JavaScript and XML
JavaScript
JavaScript  clone JavaScript
ajax
ajax  I am facing following problem, I am using ajax to get... the server using javascript. Here every time it's giving '1' only. I am unable...="text/javascript" language="javascript"> var xmlHttp
Ajax Learner - Ajax
; Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short... * Ajax is easy to learn. Ajax is based on JavaScript and existing technologies...Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer
Ajax Learner - Ajax
; Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short... application * Ajax is easy to learn. Ajax is based on JavaScript...Ajax Learner  Hi, This is Ziaul,I am working as Java/j2ee Developer
Ajax
ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used,it would be a greater advantage.After fetching data
Ajax
Ajax  i am having code in my javascript file , I want to know what is the meaning of this function ajaxFunction(url, "1"); url is given here but what is 1 here means? function populateList(element) { //alert
ajax
="index.php?q=<?php echo $this->date_format->encryption('Query','load
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
Ajax Books
for special plug-ins. Ajax is built on existing Web technologies such as JavaScript... Ajax Books       AJAX - Asynchronous JavaScript and XML - some books and resource links  These books

Ads