how to get the database value without submitting the jsp page
Hi,
I have a form that has many fields (textbox/listbox). when user enter/change a value in the first textbox, I need to pass this value to the database to check whether it exist and get the other values to be displayed to other fields in that form (i cannot get the javascript value to be pass to jsp without reload/refresh/submit. But, I need to get the user entered value, so I thought of hidden popup, iframe, etc but not sure how I could apply and which best suit this case). If I submit the page then I can easily get the value thru 'request.getParameter("fieldname") but cannot use this because I cannot submit the page.
Pls help and possible provide me with the sample coding
Thanks
hi sudharsan
u gave me that day one soln using Ajax,
<script>
function callDatabase(){
WebRemoteClient webremoteClient=new WebRemoteClient();
var inputMap=new Map();
inputMap.put("textfield1",textfield1);
webremoteClient.invoke(
--
}
</script>
just call the funtion when the value changes
<html:text property="text1" onchange='callDataBase' />
but i am not getting how to write this function in my code, plz help me, i used MS access database,
hi sudharasan i vil give my code also
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page language="java"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method=post action="emp.jsp" >
<input type="text" name="name" value="" width="20" />
<input type="text" name="gender" value="" width="10" />
<input type="text" name="num" value="" width="5" />
<input type="submit" value="Next" name="Next" />
<%! ResultSet rs; %>
<%
if(request.getMethod().equals("POST"))
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:ven");
Statement stat= con.createStatement();
String str="select gender,num from mh where names='"+request.getParameter("name")+"'";
rs=stat.executeQuery(str);
rs.next();
%>
<input type="text" name="name" value="<%= request.getParameter("name") %>" width="20" />
<input type="text" name="gender" value="<%= rs.getString(1)%>" width="10" />
<input type="text" name="num" value="<%= rs.getString(2)%>" width="5" />
<input type="submit" value="Next" name="Next" />
<%
}
catch(Exception e)
{
out.println("error" +e);
}
}
%>
</form>
</body>
</html>
you will still use javascript but with a combination with xml.. try to learn ajax
i donnt no Ajax, plz help me in case if u know AjaxThanks in advance
is this you code?<html:text property="text1" onchange='callDataBase' />
some body in this group they have told me to do like that, bt i donnt know how to do like that,
are yu using struts?.. they use struts framework..
no, i am not using any struts nor Ajax, my pblm is how do we can get the database content without submitting the jsp page, for this one person in this group have answered , by using the Ajax method callDatabase()
ok heres a sample ajax w/o jdbc..
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
<script language="javascript">
function getComboValues(combo){
var url="myservlets?combobox="+combo;
xmlHttp=GetXmlHttpObject(stateChanges);
xmlHttp.open("GET", url , false);
xmlHttp.send(null);
}
function stateChanges(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var text = xmlHttp.responseText;
document.forms[0].comboText.value=text;
}
}
function GetXmlHttpObject(handler){
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0){
alert("This example doesn't work in Opera")
return;
}
if (navigator.userAgent.indexOf("MSIE")>=0){
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5")>=0){
strName="Microsoft.XMLHTTP"
}
try{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}catch(e){
alert("Error: Scripting for ActiveX might be disabled.\nPlease enable your Scripting for ActiveX.\nClose all browser and reopen your browser. ")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0){
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}
</script>
</head>
<body>
<form>
<select name="combobox" onchange="getComboValues(this.value)">
<option value="">Select one</option>
<option value="1">Apple</option>
<option value="2">Circle</option>
<option value="3">Red</option>
<option value="4">BMW</option>
<option value="5">Basketball</option>
</select>
<input type="TEXT" name="comboText" readonly="readonly" />
</form>
</body>
</html>
myServlet.java
package com.myapp;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
public class myServlets extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String comboVal = request.getParameter("combobox");
System.out.println("comboVal: "+comboVal);
if(comboVal.equals("1")){
out.print("fruits");
}else if(comboVal.equals("2")){
out.print("shape");
}else if(comboVal.equals("3")){
out.print("color");
}else if(comboVal.equals("4")){
out.print("car");
}else if(comboVal.equals("5")){
out.print("game");
}
out.close();
}
}
in web.xml:
<servlet-mapping>
<servlet-name>myServlets</servlet-name>
<url-pattern>/myservlets</url-pattern>
</servlet-mapping>
i tryed ur example , but i am not getting any output, hey i want to get the database content without submitting the jsp form, i tryed using java script but it cann't possible to connect database using javascript, somebody in this group gave me the Ajax method , see below,
<script>
function callDatabase(){
WebRemoteClient webremoteClient=new WebRemoteClient();
var inputMap=new Map();
inputMap.put("textfield1",textfield1);
webremoteClient.invoke(
--
}
</script>
just call the funtion when the value changes
<html:text property="text1" onchange='callDataBase' />
and call the javascript Ajax function from onChange of that textfield....
what errors are you getting.. that is a simple ajax implementation..
deployment of that page itself is failed in netbeans IDE
maybe you have problem pasting code.. and i have a worng filename that i gave.. the myServlet.java should be myServlets.java in com.myapp package.. i made the codes on Jdeveloper 10.1.2 and tested it also on Netbeans 5.. i have no problem on running the codes:)
Hi Mahantesh...What framework your using .......is that struts or simple jsps?if jsps,still you can use ajax....Just search it on web...for simple ajax.code...there are many codes available...its async java and xml....
thanx for ur reply, i searched in net i am not getting, i am using only jsp, u gave me that day Ajax method callDatabase() , if possible give me coplete solution to this using that method
thanks in advance
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page language="java"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method=post action="emp.jsp" >
<input type="text" name="name" value="" width="20" />
<input type="text" name="gender" value="" width="10" />
<input type="text" name="num" value="" width="5" />
<input type="submit" value="Next" name="Next" />
<%! ResultSet rs; %>
<%
if(request.getMethod().equals("POST"))
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:ven");
Statement stat= con.createStatement();
String str="select gender,num from mh where names='"+request.getParameter("name")+"'";
rs=stat.executeQuery(str);
rs.next();
%>
<input type="text" name="name" value="<%= request.getParameter("name") %>" width="20" />
<input type="text" name="gender" value="<%= rs.getString(1)%>" width="10" />
<input type="text" name="num" value="<%= rs.getString(2)%>" width="5" />
<input type="submit" value="Next" name="Next" />
<%
}
catch(Exception e)
{
out.println("error" +e);
}
}
%>
</form>
</body>
</html>
some one pasted over there the simple code for ajax rite?you can use the same ..there are lots of examples...on the web man....just search for ajax source code on google. Else will get that to you later..tied up to someother work.
hello problem still not solved?.. did you ever try to debug the codes that i gave you.. if you have ran it, i still can help you with the database access..
hey jgalacambra plz i am not getting soln for this pblm, plz help me , i made one drop down menu for employee id's, as soon as i select the id from drop down menu, i have to get the values of the other textfields from database, plz help me
the codes that i gave you is just a simple ajax implementation.. please try to make it run first so i can give you the next codes.. a little bit more complicated.. if the first code wont run then next next i think will not run too..
i found nice explanation of web application using Ajax, plz go through this link and plz tell me how to write servlet FormServlet, he made link to zip file but permission is denaied to view that site
this is the site address http://www.regdeveloper.com/2006/06/20/ajax_web_tutorial_part2/
ok lets stick to my codes..what ide are you using?
so far here are the codes that i have created using netbeans 5
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>myServlets</servlet-name>
<servlet-class>com.myapp.myServlets</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlets</servlet-name>
<url-pattern>/myservlets</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
index.jsp
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
<script language="javascript">
function getComboValues(combo){
var url="myservlets?combobox="+combo;
xmlHttp=GetXmlHttpObject(stateChanges);
xmlHttp.open("GET", url , false);
xmlHttp.send(null);
}
function stateChanges(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var text = xmlHttp.responseText;
document.forms[0].comboText.value=text;
}
}
function GetXmlHttpObject(handler){
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0){
alert("This example doesn't work in Opera")
return;
}
if (navigator.userAgent.indexOf("MSIE")>=0){
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5")>=0){
strName="Microsoft.XMLHTTP"
}
try{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}catch(e){
alert("Error: Scripting for ActiveX might be disabled.\nPlease enable your Scripting for ActiveX.\nClose all browser and reopen your browser. ")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0){
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}
</script>
</head>
<body>
<form>
<select name="combobox" onchange="getComboValues(this.value)">
<option value="">Select one</option>
<option value="1">Apple</option>
<option value="2">Circle</option>
<option value="3">Red</option>
<option value="4">BMW</option>
<option value="5">Basketball</option>
</select>
<input type="TEXT" name="comboText" readonly="readonly" />
</form>
</body>
</html>
myServlets.java
package com.myapp;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
public class myServlets extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String comboVal = request.getParameter("combobox");
System.out.println("comboVal: "+comboVal);
if(comboVal.equals("1")){
out.print("fruits");
}else if(comboVal.equals("2")){
out.print("shape");
}else if(comboVal.equals("3")){
out.print("color");
}else if(comboVal.equals("4")){
out.print("car");
}else if(comboVal.equals("5")){
out.print("game");
}
out.close();
}
}
try to run this on your netbeans
thanks jgalacambra i got the nice out put,in the same way i am trying to get the values from the database, but i am not getting, i am using netbeans IDE 5.0
ok here's another:
index1.jsp
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
<script language="javascript">
function getComboValues(combo,combo1val,combo2val){
//alert(combo)
if(combo=="first"){
document.forms[0].comboname.value="brand";
document.getElementById("color").length++;
document.getElementById("model").length++;
}else if(combo=="second"){
document.forms[0].comboname.value="model";
document.getElementById("color").length=0;
document.getElementById("color").length++;
}else if(combo=="third"){
combo1val = document.getElementById("brand").value;
document.forms[0].comboname.value="color";
}
var url="myServlet?combo="+combo+"&combo1val="+combo1val+"&combo2val="+combo2val;
xmlHttp=GetXmlHttpObject(stateChanges);
xmlHttp.open("GET", url , false);
xmlHttp.send(null);
}
function getText(){
var url="myServlet";
xmlHttp=GetXmlHttpObject(stateChangeA);
xmlHttp.open("POST", url , false);
xmlHttp.send(null);
}
function stateChanges(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var text = xmlHttp.responseText;
var textVal = "";
var comboname = document.forms[0].comboname.value;
document.getElementById(comboname).length=1;
for(var x = 1;x<=parseFloat(text.substring(text.lastIndexOf("|")+1,text.length));x++){
document.getElementById(comboname).length++;
textVal = text.substring(0,text.indexOf("|"));
text = text.substring(text.indexOf("|")+1,text.length);
document.getElementById(comboname).options[x].value=textVal;
document.getElementById(comboname).options[x].text=textVal;
}
}
}
function stateChangeA(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("mytexts").innerHTML = "";
var text = xmlHttp.responseText;
document.getElementById("mytexts").innerHTML = text;
}
}
function GetXmlHttpObject(handler){
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0){
alert("This example doesn't work in Opera")
return;
}
if (navigator.userAgent.indexOf("MSIE")>=0){
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5")>=0){
strName="Microsoft.XMLHTTP"
}
try{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}catch(e){
alert("Error: Scripting for ActiveX might be disabled.\nPlease enable your Scripting for ActiveX.\nClose all browser and reopen your browser. ")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0){
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}
function getValue(){
alert(document.getElementById("mytext").value);
}
</script>
</head>
<body onload="getComboValues('first','','');getText();">
<form>
<table cellspacing="0" cellpadding="2" border="0" width="400">
<tr>
<td>Car Brand</td>
<td>
<select name="brand" id="brand" onchange="getComboValues('second',this.value,'')"/>
</td>
</tr>
<tr>
<td>Model</td>
<td>
<select name="model" id="model" onchange="getComboValues('third','',this.value)"/>
</td>
</tr>
<tr>
<td>Color</td>
<td>
<select name="color" id="color"/>
</td>
</tr>
</table>
<input type="hidden" name="comboname"/>
<div id="mytexts">
</div>
</form>
</body>
</html>
MyServlet.java
package mypackage5;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
public class MyServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
HelperClass helper = new HelperClass();
PrintWriter out = response.getWriter();
String combo2Val = request.getParameter("combo2val")!=null?request.getParameter("combo2val"):"";
String combo1Val = request.getParameter("combo1val")!=null?request.getParameter("combo1val"):"";
String combo = request.getParameter("combo")!=null?request.getParameter("combo"):"";
String cars = "";
if(combo.equals("first")){
cars = helper.getCarBrand();
}else if(combo.equals("second")){
cars = helper.getCarModel(combo1Val);
}else if(combo.equals("third")){
cars = helper.getCarColor(combo1Val,combo2Val);
}
out.print(cars);
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
System.out.println("here");
out.println("<input type=\"text\" name=\"mytext\" id=\"mytext\" value=\"Sample\">");
out.println("<input type=\"button\" onclick=\"getValue()\" value=\"Get My Value\">");
out.close();
}
}
HelperClass.java
package mypackage5;
import java.sql.*;
public class HelperClass
{
public HelperClass()
{
}
public String getCarBrand(){
String brands = "";
int x = 0;
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/market","root","");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select vehiclebrand from vehicle group by vehiclebrand");
while(rs.next()){
brands= brands + rs.getString(1) +"|";
x++;
}
conn.close();
} catch (Exception ex)
{
ex.printStackTrace();
}
return brands+""+x;
}
public String getCarModel(String brand){
String models = "";
int x = 0;
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/market","root","");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select vehiclename from vehicle where vehiclebrand = '"+brand+"' group by vehiclebrand,vehiclename");
while(rs.next()){
models = models +rs.getString(1) +"|";
x++;
}
conn.close();
} catch (Exception ex)
{
ex.printStackTrace();
}
return models+""+x;
}
public String getCarColor(String brand,String model){
String colors = "";
int x = 0;
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/market","root","");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select vehiclecolor from vehicle where vehiclebrand = '"+brand+"' and vehiclename = '"+model+"' group by vehiclebrand,vehiclename,vehiclecolor");
while(rs.next()){
colors = colors+rs.getString(1)+"|";
x++;
}
conn.close();
} catch (Exception ex)
{
ex.printStackTrace();
}
return colors+""+x;
}
}
in web.xml:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>mypackage5.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/myServlet</url-pattern>
</servlet-mapping>
i am not getting, i created the table, and i complied both java bean and servlet and then run the jsp, i got http error 500,
did you try the previously posted codes?
yes i tryed and also i get the output, i am now trying to my application, thanks a lot
ok.. if you ever encountered another problem with the codes.. just tell me
ok, give me ur any email ID's for communication
i can give you my personal email add later.. for now i been having trouble with my company to access my email.. maybe next week
ok, hey how can i change that combobox to textfield, in ur last example i changed last combo box for color to textfield, but i am not getting the any output on textfield, can u plz tell me where i have to change the code in ur sample code
there are two ways in which i access the servlet
this:
xmlHttp.open("GET", url , false);
which access the doGet method
and this:
xmlHttp.open("POST", url , false);
which access the doPost method in the servlet
as you can see in ht servlet the cars in the out.print and the string inside the out.println methods are the one that is being sent back by the servlet.
this part message sent back by the servlet through the variable text
var text = xmlHttp.responseText;
and this one is the one that will populate the comboxes
var textVal = "";
var comboname = document.forms[0].comboname.value;
document.getElementById(comboname).length=1;
for(var x = 1;x<=parseFloat(text.substring(text.lastIndexOf("|")+1,text.length));x++){
document.getElementById(comboname).length++;
textVal = text.substring(0,text.indexOf("|"));
text = text.substring(text.indexOf("|")+1,text.length);
document.getElementById(comboname).options[x].value=textVal;
document.getElementById(comboname).options[x].text=textVal;
}
now as you can notice the varibale text holds the message. you can put the value of the text to a textfield by just adding document.getElementById("textfield").value =text;
after this part:
var textVal = "";
var comboname = document.forms[0].comboname.value;
document.getElementById(comboname).length=1;
for(var x = 1;x<=parseFloat(text.substring(text.lastIndexOf("|")+1,text.length));x++){
document.getElementById(comboname).length++;
textVal = text.substring(0,text.indexOf("|"));
text = text.substring(text.indexOf("|")+1,text.length);
document.getElementById(comboname).options[x].value=textVal;
document.getElementById(comboname).options[x].text=textVal;
}
and put this inside the form:
<input type="text" name="textfield" id="textfield">
no, i want to display that color name in textfield instead of displaying it in combo box, as soon as i select car brand and model i have to display the car color in textfield
yes just follow the steps that i gave.. you will get what i said
still i am getting color field as combo box, i tryed twice, i am not getting, i want to display automitacally as soon as i select the car brand and model, what u had give in that i am getting no of elements in the first combo box,after i choosing in the first it is displaying 1 in that textfield
did you create the tables? and populate the tables in you db?.. the values are fetch from mysql db
yaa i created the table in ms access, i just want to display color of the particular selected car brand and model in textfield insted of getting it in combo box, i think this time u can undertaqnd my pblm easily
yup sorry.. i made different color for a given car brand and model that is why i put it in the combobox
yaa i know that, i am choosing brand as well as model of the car, i am getting only one color, that color i want display it in text field,insted of getting in the combo box
replace the jsp with this one:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
<script language="javascript">
function getComboValues(combo,combo1val,combo2val){
//alert(combo)
if(combo=="first"){
document.forms[0].comboname.value="brand";
document.getElementById("color").length++;
document.getElementById("model").length++;
}else if(combo=="second"){
document.forms[0].comboname.value="model";
document.getElementById("color").length=0;
document.getElementById("color").length++;
}else if(combo=="third"){
combo1val = document.getElementById("brand").value;
document.forms[0].comboname.value="color";
}
var url="myServlet?combo="+combo+"&combo1val="+combo1val+"&combo2val="+combo2val;
xmlHttp=GetXmlHttpObject(stateChanges);
xmlHttp.open("GET", url , false);
xmlHttp.send(null);
}
function getText(){
var url="myServlet";
xmlHttp=GetXmlHttpObject(stateChangeA);
xmlHttp.open("POST", url , false);
xmlHttp.send(null);
}
function stateChanges(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var text = xmlHttp.responseText;
var tempText = text;
var textVal = "";
var comboname = document.forms[0].comboname.value;
document.getElementById(comboname).length=1;
for(var x = 1;x<=parseFloat(text.substring(text.lastIndexOf("|")+1,text.length));x++){
document.getElementById(comboname).length++;
textVal = text.substring(0,text.indexOf("|"));
text = text.substring(text.indexOf("|")+1,text.length);
document.getElementById(comboname).options[x].value=textVal;
document.getElementById(comboname).options[x].text=textVal;
}
if(comboname=="color"){
document.getElementById("textfield").value=tempText;
}
}
}
function stateChangeA(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("mytexts").innerHTML = "";
var text = xmlHttp.responseText;
document.getElementById("mytexts").innerHTML = text;
}
}
function GetXmlHttpObject(handler){
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0){
alert("This example doesn't work in Opera")
return;
}
if (navigator.userAgent.indexOf("MSIE")>=0){
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5")>=0){
strName="Microsoft.XMLHTTP"
}
try{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}catch(e){
alert("Error: Scripting for ActiveX might be disabled.\nPlease enable your Scripting for ActiveX.\nClose all browser and reopen your browser. ")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0){
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}
function getValue(){
alert(document.getElementById("mytext").value);
}
</script>
</head>
<body onload="getComboValues('first','','');getText();">
<form>
<table cellspacing="0" cellpadding="2" border="0" width="400">
<tr>
<td>Car Brand</td>
<td>
<select name="brand" id="brand" onchange="getComboValues('second',this.value,'')"/>
</td>
</tr>
<tr>
<td>Model</td>
<td>
<select name="model" id="model" onchange="getComboValues('third','',this.value)"/>
</td>
</tr>
<tr>
<td>Color</td>
<td>
<select name="color" id="color"/>
</td>
</tr>
</table>
<input type="hidden" name="comboname"/>
<input type="text" name="textfield" id="textfield"/>
<div id="mytexts">
</div>
</form>
</body>
</html>
hi jgalacambra , is it possible this pblm by jstl , if possible tell me how to do that, and also tell me how to start jstl, i donnt know anthing abt this JSTLplz help me,
ajax is an javascript and xml thing.. it has nothing to do with jstl...jstl tutorials: http://www.google.com/search?complete=1&hl=en&q=jstl+tutorial&btnG=Google+Search
hey jgalacambra is it possible to extend the interface? if possible how did u extend the interface tell me?
you do not extend interface you implement it
yesterday i gave one inerview, in that they were asked me this question, and i gave the same answer what u told me, they are in doubt mood, and asked one more quetion, vill it possible to call servlet from jsp? i said yes its possible by including that servlet file in jsp by using include derctive, then they were asked is there any other methods other than this, i told them i donnt know, do u know other method of calling servlet in jsp?
i don't know of any.. have the same knowledge.. heheh.. but you can extend a servlet in your jsp maybe they are talking about that(not sure)..