Javascript & AJAX query

Ads
 

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

Ads









Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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
ajax
ajax  please describe the ajax
Ajax
Ajax  How to learn AJAX
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
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      
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
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
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  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
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. 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
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... 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  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
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly   index.html <...="javascript" type="text/javascript"> function diplayFunction(){ var
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
Ajax Books
Ajax Books       AJAX - Asynchronous JavaScript and XML - some books and resource links  These books and resources will help you stay on top of AJAX happenings Up until now
JavaScript
JavaScript  clone JavaScript
ajax example
WITH EXAMPLE?  Hi friend, Ajax : Asynchronous JavaScript and XML...Ajax Example Here is the list of few Ajax examples at RoseIndia.net. Ajax example Ajax example   Hi, Where can I find Ajax example
AJAX Geek
AJAX Geek       All things ajax, css, dhtml, xml, javascript, and geekier Read full Description

Ads