problems in passing values from jsp to javascript at second attempt.values are not visual after selecting a particular one.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ganesh_R
Posted On:   Sunday, February 28, 2010 03:08 AM

]]>]]> First page : Task1.html Select a Program:               < unbounded Program 1 Program 2 Program info will be listed here. Second page : Task11.js var xmlhttp function showCustomer(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="Task123.jsp";    More>>

First page : Task1.html





















Select a Program:               <







Program info will be listed here.










Second page : Task11.js






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


(in this page onchange method only im getting the problem,cant able to post value from this method to javascript).






<%@ page import="java.sql.*" %>

<%

String connectionURL = "jdbc:mysql://localhost/new";

Connection connection = null;

Statement statement;

ResultSet rs;

%>













<%

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");

%>




Projects for Program are :  




<%

while(rs.next())

{

String result=rs.getString(1);

String home="unbounded";

%>

<%

out.println(s+" consist of :
");

if(targetId.equalsIgnoreCase("unbounded"))

{%>

<%= home %>">

<% out.println(home); %>



<%}

else if(targetId.equalsIgnoreCase("Program 1"))

{%>

<%= result %>">

<% out.println(result); %>



<%}

else

{%>

<%= result %>">

<% out.println(result); %>



<%}

}

%>










Forth page : Task113.js








var xmlhttp


function showCustomer(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;

}



Final page : dummy.jsp








<%@ page import="java.sql.*" %>

<%

String connectionURL = "jdbc:mysql://localhost/new";

Connection connection = null;

Statement statement1 = null;

ResultSet rs1 = null;

%>





<%

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 = statement1.executeQuery("SELECT * FROM task1 where prid='"+s1+"'");

%>



<%while(rs1.next())
{%>







<%

}

%>


<%

out.println(rs1.getString("tid")+"
");

%>



<%

out.println(rs1.getString("tname")+"
");

%>



<%

out.println(rs1.getString("prid")+"
");

%>

<%


rs1.close();


%>





   <<Less
About | Sitemap | Contact