Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax Jsp and ajax
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sakthilakshmi
Jsp and ajax
1 Answer(s)      2 years and 4 months ago
Posted in : Ajax


Hi

I am using jsp and ajax.I am retrieving the entire content from database(al.jsp) and put it into a textbox.When i am clicking a combo box,it updates the selected value in the database(jag.jsp).

But it only works for first textbox and combobox.I noticed that it requires different id for textbox and combobox. But i am not able to assign unique id.

Here is my code. Plz anybody help me.Its urgent.

al.jsp
<%@ page import="java.sql.*" %>
<%@ page import="javax.swing.*" %>
<%! Connection c;
Statement s;
ResultSet rs;
String cid,roll; 
int i=0;
int j=1;
%>
<% try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("jdbc:odbc:comdsn1");
s=c.createStatement();
rs=s.executeQuery("select * from comt1");
}
catch(Exception e)
{} %>
<html>

<script>

function ajax(str){
var xmlHttp;
var i;
var config=document.getElementById('comboBoxMenu').value;
var config1=document.getElementById('t1').value;
var tids=document.getElementById('comboBoxMenu').getAttribute('id');
alert("coboid:"+tids);

try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlHttp=new XMLHttpRequest();
}
catch(e){
alert("your browser cant support");
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4 && xmlhttp.status==200){
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
document.write(xmlHttp.responseText);
}
}
var url="jag.jsp";
url=url+"?q="+config+"&q1="+config1;

xmlHttp.open("POST",url,true);
xmlHttp.send(url);
}
</script>

<body>
<form method="post" name="jag">
<center><table>
<% 
try
{
    rs=s.executeQuery("select * from comt1");

while(rs.next())
{
    roll=rs.getString("rollno");
    i=i+1;
    j=j+1;
%>
<tr><td><input type="text" value="<%=roll%>" name="t1" id="${i}" readonly></td><td>

<select name="comboBoxMenu" id="${j}" onchange="ajax(this.value);">

<option value="present">present</option>
<option value="absent">absent</option>
</select>

</td>
<td></tr>

<% }
}
catch(Exception e){}
%>
</table>
</center>
</form>
<div id="myDiv">

  </div>

</body>
</html>
jag.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ page import="java.sql.*" %>
<%@ page import="javax.swing.*" %>


<% String s1=request.getParameter("q");
String s2=request.getParameter("q1");

 %>




<%try{
    Connection c;
    Statement st;
    ResultSet rs;

        JOptionPane.showMessageDialog(null,"welcome"); 
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    c=DriverManager.getConnection("jdbc:odbc:comdsn1");

    st=c.createStatement();
     rs=st.executeQuery("select * from comt1");
    JOptionPane.showMessageDialog(null,"welcome updated"+s2+s1);
    st.executeUpdate("update comt1 set [9-10]='"+s1+"' where rollno='"+s2+"'");
    rs=st.executeQuery("select * from comt1");

   JOptionPane.showMessageDialog(null,"updated");

}

catch(Exception ex){

out.println(ex);

}


%>

Thanks in advance.Anybody help me.its urgent plz.

Advertisement
View Answers

June 15, 2012 at 4:01 PM


Hi,I am sakthilakshmi. Try this code.I think its useful for u.

<html>

<script>

function ajax(str){
var xmlHttp;

var config=document.getElementById('comboBoxMenu').value;


try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlHttp=new XMLHttpRequest();
}
catch(e){
alert("your browser cant support");
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4 && xmlhttp.status==200){
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
document.write(xmlHttp.responseText);
}
}
var url="jag.jsp";
url=url+"?q="+config;

xmlHttp.open("POST",url,true);
xmlHttp.send(url);
}
</script>

<body>
<form method="post" name="jag">

<select name="comboBoxMenu" onchange="ajax(this.value);">

<option value="present">present</option>
<option value="absent">absent</option>
</select>



</form>
<div id="myDiv">

  </div>

</body>
</html>
jag.jsp
<html>

<% String s1=request.getParameter("q");
out.println(s1); //will display the combo box value

 %>
</html>


Related Tutorials/Questions & Answers:
jsp & ajax
jsp & ajax  how to enable or disable textbox using radio buttons by using jsp and ajax? plz help me.... i m new in jsp & ajax
jsp and ajax
jsp and ajax  how to enable or disable textbox using radio buttons by using jsp and ajax
Advertisements
ajax jsp - Ajax
ajax jsp  multiple combo with ajax using jsp?  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/jsp/comboSelect.shtml Thanks
Ajax with jsp - Ajax
Ajax with jsp  multiple combo boxes with ajax in jsp?  Hi friend, I am sending you a link. I hope that, this link will help you. Please visit for more information. http://www.roseindia.net/jsp
using jsp's....and ajax - Ajax
using jsp's....and ajax  Hi, i need code using ajax .....in a text box when i enter an alphabet i should get list of words starts with the alphabet given in the text box
jsp - Ajax
jsp  I'm very new in using the jsp and ajax, i have some JSP pages and i need to add some ajax features in my jsp page, for the example i need.... How can I implement this and then add this to my jsp page? please
ajax code with jsp - Ajax
ajax code with jsp  hi , Sorry for insufficient data.i m making some correction on question. I have to perform some calculation on my jsp page. i want to do it automatically (using ajax in jsp). problem is - i hv two
ajax and jsp code - Ajax
ajax and jsp code  can u please give me the code for retriving the data from database using ajax our requriment is if i select country name in listbox display the corresponding all the states. using jsp and ajax   
JSP and AJAX very urgent - Ajax
JSP and AJAX very urgent  Hi Team, This is Ragavendran.R.. I have a very basic doubt in AJAX. While Using AJAX, of course, there will be tag involved in JSP page. But in my current project, I am using too many tags
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
Jsp and ajax
Jsp and ajax  Hi I am using jsp and ajax.I am retrieving...; function ajax(str){ var xmlHttp; var i; var config=document.getElementById..."; url=url+"?q="+config+"&q1="+config1; xmlHttp.open("POST",url,true
ajax in jsp
ajax in jsp  i m not able to compare string with the responseText value, though the value in the responsetext is of string type. login.jsp: print("<html> <head> <meta http-equiv="Content-Type" content="text
ajax in jsp
ajax in jsp  i m not able to compare string with the responseText value, though the value in the responsetext is of string type. my code: login.jsp <html> <head> <meta http-equiv
jsp and ajax - JSP-Servlet
jsp and ajax  i had some problem i want to display the current... to be automatically updated for every second for that i want to make an ajax call.../jsp/fileupload.shtml Thanks
JSP and AJAX- very urgent - Ajax
JSP and AJAX- very urgent  Respected Sir/Madam, I am... (Using AJAX. for ur reference, I have included the coding below: Login.html... not support AJAX!"); return; } var url="check.jsp"; url=url+"?id="+alpha
ajax code for jsp
ajax code for jsp  How to write ajax code to retrieve information on to particular part of webpage when we select option from drop down box
code for jsp - Ajax
country.By using jsp and Ajax.    Hello Friend I send the code you...code for jsp  please give code for using jsp page and Ajax.Retrive... getDetail(source,div){ getData(source,div); } An Ajax Demo
Ajac code with jsp - Ajax
Ajac code with jsp  hi , i am beginner for ajax.I have to perform some calculation on my jsp page. i want to do it automatically that is possible using ajax. problem is - i hv two text box. 1st take
ajax in java - JSP-Servlet
ajax in java  The below code is for a php page but I want this in JSP page. function postRequest(strURL){ var xmlHttp...: "login.php"   Hi friend, Do some changes to convert in JSP
Ajax validation - JSP-Servlet
Ajax validation  How to fade out the images when an onblur function is called moving from a text box to another?? can anyone help out with with the code
The AJAX JSP Tag Library
The AJAX JSP Tag Library       The AJAX JSP Tag Library is a set of JSP tags that simplify the use of Asynchronous JavaScript and XML (AJAX) technology in JavaServer Pages. This tag
Ajax - JSP-Servlet
Ajax  Simple ajax code for getting one text box value  Hi friend, Code to help in solving the problem : function postRequest... on Ajax visit to : http://www.roseindia.net/ajax/ Thanks
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate... the city. I am doing it through two jsp pages only. Country1.jsp : <%@ page
DropDown and text boxes with AJAX, JSP - Ajax
present. we are already using jsp's and java technology. can we integrate ajax in jsp's to achieve the same? if so could you please guide me to achive the same...DropDown and text boxes with AJAX, JSP  Hi, we are using one drop
refresh jsp page - Ajax
refresh jsp page  Code for refresh a web page in jsp.  Hi friend, function refreshpage() { window.location.reload
Ajax using jsp
Ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import...); } %> Is there Any error...........In first Page I use ajax for displaying
ajax using jsp
ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="java.lang.*" %> <
datagid with paging using jsp - Ajax
datagid with paging using jsp  datagrid with paging using ajax and jsp  Hi friend, For read more information : http://www.roseindia.net/jsp/data-grid.shtml Thanks
Ajax not working in jsp
Ajax not working in jsp  I'm using Netbean, Ajax validation in the following code is not working the code succesfully run for first UID validation...; frmMain.elements[i].valid; } } return blnValid; } //if Ajax
 

 

 

DMCA.com