The following are the program i did......
and the problem im getting is object expected in onchange function at line 27(where i marked that one in bold for ur ease of identifying the error occuring area) in Task123.jsp. The value in not passed from Task123.jsp to Task113.js.
First Page : Task1.html
second page : Task11.js
Third page : Task123.jsp
Forth page : Task113.js
Fifth and the Final page : dummy.jsp
eagerly waiting for ur quick reply.thanks in advance.
and the problem im getting is object expected in onchange function at line 27(where i marked that one in bold for ur ease of identifying the error occuring area) in Task123.jsp. The value in not passed from Task123.jsp to Task113.js.
First Page : Task1.html
Code:
<html> <head> <script type="text/javascript" src="Task11.js"> </script> </head> <body> <form name="myform" method="post" action=""> Select a Program: <select name="text1" style="width: 100px" onchange="showCustomer(document.myform.text1.value)"> <option value="unbounded">unbounded</option> <option value="Program 1">Program 1</option> <option value="Program 2">Program 2</option> </select> </form> <div id="txtHint"><b>Program info will be listed here.</b></div> </body> </html>
second page : Task11.js
Code:
var xmlhttp
function showCustomer(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="Task123.jsp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
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()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
Third page : Task123.jsp
Code:
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost/new";
Connection connection = null;
Statement statement;
ResultSet rs;
%>
<html>
<head>
<script type="text/javascript" src="Task113.js">
</script>
</head>
<body>
<%
String s=request.getParameter("q");
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "cng");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT prid FROM project where pid='"+s+"'");
String targetId=request.getParameter("q");
%>
<form name="myform1" method="post" action="Task113.jsp">
Projects for Program are :
<select name="project" id="project" style="width: 100px" [B]onChange="showCustomer6(document.myform1.project.value)[/B]">
<%
while(rs.next())
{
String result=rs.getString(1);
String home="unbounded";
%>
<%
out.println(s+" consist of :<br>");
if(targetId.equalsIgnoreCase("unbounded"))
{%>
<option value="<%= home %>">
<% out.println(home); %>
</option>
<%}
else if(targetId.equalsIgnoreCase("Program 1"))
{%>
<option value="<%= result %>">
<% out.println(result); %>
</option>
<%}
else
{%>
<option value="<%= result %>">
<% out.println(result); %>
</option>
<%}
}
%>
</select>
</form>
</body></html>
Code:
var xmlhttp
function showCustomer6(str)
{
alert("1");
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="dummy.jsp";
url=url+"?q1="+str;
url=url+"&sid="+Math.random();
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()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
Code:
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost/new";
Connection connection = null;
Statement statement1 = null;
ResultSet rs1 = null;
%>
<html><body>
<%
String s1=request.getParameter("q1");
out.println("String is "+s1);
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "cng");
statement1 = connection.createStatement();
rs1 = statement.executeQuery("SELECT * FROM task1 where prid='"+s1+"'");
%>
<table border=1>
<%while(rs1.next()) {%>
<tr><td>
<%
out.println(rs1.getString("tid")+"<br>");
%>
</td>
</tr><tr><td>
<%
out.println(rs1.getString("tname")+"<br>");
%>
</td>
</tr><tr><td>
<%
out.println(rs1.getString("prid")+"<br>");
%>
</td>
</tr><%
}
%></table><%
rs1.close();
%>
</body></html>.
Comment