Ajax code for Select Your Question tag
MAIN PAGE.html
-------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html:html>
<script src="sub.js"></script>
<head>
<title>Main..,</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<form action="" method="post">
<select name="question" onchange="showCustomer(this.value)">
<option value="What is the name of your best friend from childhood?">What is the name of your best friend from childhood?</option>
<option value="What was the name of your first teacher?">What was the name of your first teacher?</option>
<option value="What is the name of your manager at your first job?">What is the name of your manager at your first job?</option>
<option value="What was your first phone number?">What was your first phone number?</option>
<option value="What is your vehicle registration number?">What is your vehicle registration number?</option>
<option style="font-style: italic;" value="ownquestions">Write my own question</option>
</select>
<div id="txtHint"></div>
</form>
</body>
</html:html>
----------------------------------------------------------------------------------------------------------
sub.js
var xmlHttp
function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="sub.jsp";
url=url+"?question="+str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
----------------------------------------------------------------------------------------------------
sub.html/jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ page language = "java" import="java.sql.*,java.util.*,java.io.*,java.awt.*" %>
<html:html>
<head>
<script src="sub.js"></script>
<title>sub</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
hi...
<%
if(request.getParameter("question").equalsIgnoreCase("ownquestions"))
{
out.print("<br><input type='text' name='question'> </input><br><br>");
}
%>
</body>
</html:html>
-------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html:html>
<script src="sub.js"></script>
<head>
<title>Main..,</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<form action="" method="post">
<select name="question" onchange="showCustomer(this.value)">
<option value="What is the name of your best friend from childhood?">What is the name of your best friend from childhood?</option>
<option value="What was the name of your first teacher?">What was the name of your first teacher?</option>
<option value="What is the name of your manager at your first job?">What is the name of your manager at your first job?</option>
<option value="What was your first phone number?">What was your first phone number?</option>
<option value="What is your vehicle registration number?">What is your vehicle registration number?</option>
<option style="font-style: italic;" value="ownquestions">Write my own question</option>
</select>
<div id="txtHint"></div>
</form>
</body>
</html:html>
----------------------------------------------------------------------------------------------------------
sub.js
var xmlHttp
function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="sub.jsp";
url=url+"?question="+str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
----------------------------------------------------------------------------------------------------
sub.html/jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ page language = "java" import="java.sql.*,java.util.*,java.io.*,java.awt.*" %>
<html:html>
<head>
<script src="sub.js"></script>
<title>sub</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
hi...
<%
if(request.getParameter("question").equalsIgnoreCase("ownquestions"))
{
out.print("<br><input type='text' name='question'> </input><br><br>");
}
%>
</body>
</html:html>
Comments
Post a Comment