Initilly load some datas into dropdown list. It contain company code and company related fields in Textbox.
Using Ajax to load the company related Fields in onchange Function
I edit the company related fields and update it. Its updated Successfully then i Click the back button and refresh the browser.
I select the updated company form the dropdown list. It always list the old value insted of updated data.
I want to show the updated fields into corresponding textbox.
This part of coding is to load the companyname into dropdown list
<%
DBAccess dbAccess = Util.initDatabaseAccess();
ResultSet rs = null;
ResultSet rsEdit = null;
int updateSuccess = 0;
String button = request.getParameter("saveAction");
rs = dbAccess.executeQuery("select companyname,Companycode,companyid from yosemitecompany where cmpstatus=1 order by companyname");
%>
My Ajax function
<script>
function showCompanyDetails(str) {
if (str=="") {
document.getElementById("CompanyName").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var resValue=new Array();
resValue = xmlhttp.responseText.split("$");
document.getElementById("CompanyName").value=resValue[0];
document.getElementById("StreetName1").value=(resValue[1]!=null && !resValue[1].equalsIgnoreCase("null") && resValue[1].length>0?resValue[1]:"");
document.getElementById("StreetName2").value=(resValue[2]!=null && !resValue[2].equalsIgnoreCase("null") && resValue[2].length>0?resValue[2]:"");
document.getElementById("City").value=(resValue[3]!=null && !resValue[3].equalsIgnoreCase("null") && resValue[3].length>0?resValue[3]:"");
document.getElementById("Zipcode").value=trim((resValue[5]!=null && !resValue[5].equalsIgnoreCase("null") && resValue[5].length>0?resValue[5]:""));
document.getElementById("officePhone").value=(resValue[6]!=null && !resValue[6].equalsIgnoreCase("null") && resValue[6].length>0?resValue[6]:"");
document.getElementById("Fax1").value=(resValue[7]!=null && !resValue[7].equalsIgnoreCase("null") && resValue[7].length>0?resValue[7]:"");
document.getElementById("email").value=(resValue[8]!=null && !resValue[8].equalsIgnoreCase("null") && resValue[8].length>0?resValue[8]:"");
document.getElementById("WebSite").value=(resValue[9]!=null && !resValue[9].equalsIgnoreCase("null") && resValue[9].length>0?resValue[9]:"");
document.getElementById("description").value=(resValue[10]!=null && !resValue[10].equalsIgnoreCase("null") && resValue[10].length>0?resValue[10]:"");
document.getElementById("companycode").value=resValue[11];
document.getElementById("tempCompanyId").value=resValue[12];
document.getElementById("tempStateId").value=resValue[13];
stateID = resValue[13];
countryID = resValue[14];
processAjaxRequestPost('ajaxRequestPost','SingleListHandler','getCountryListDetails', document.getElementById("tempCompanyId").value);
showTimezone(resValue[15]);
document.getElementById("userName").value=resValue[16];
document.getElementById("passWord").value=resValue[17];
}
}
xmlhttp.open("GET","customerDetail.jsp?val="+str,true);
xmlhttp.send();
}
</script>
My Update function
<%if(updateSuccess <= 0){
if(button != null && button.equalsIgnoreCase("update")) {
String companyCode = request.getParameter("companycode").trim();
String companyName = request.getParameter("CompanyName").trim();
String StreetName1 = request.getParameter("StreetName1").trim();
String StreetName2 = request.getParameter("StreetName2").trim();
String City = request.getParameter("City").trim();
String Zipcode = request.getParameter("Zipcode").trim();
String officePhone = request.getParameter("officePhone").trim();
String Fax1 = request.getParameter("Fax1").trim();
String email = request.getParameter("email").trim();
String WebSite = request.getParameter("WebSite").trim();
String description = request.getParameter("description").trim();
String companyid = request.getParameter("tempCompanyId").trim();
String stateId = request.getParameter("tempStateId").trim();
String timeZone = request.getParameter("timezone").trim();
String uploadCustomerLogo = request.getParameter("uploadCustomerLogo").trim();
String userName = request.getParameter("userName").trim();
String passWord = request.getParameter("passWord").trim();
String smtpInsertFlag = "NO";
String getCompanyId = null;
updateSuccess = dbAccess.executeUpdate("update yosemitecompany set companyname='"+com.zoniac.util.Util.deQuoteForSingleQuote(companyName)+"', streetname1='"+com.zoniac.util.Util.deQuoteForSingleQuote(StreetName1)+"', streetname2='"+com.zoniac.util.Util.deQuoteForSingleQuote(StreetName2)+"', cityname='"+com.zoniac.util.Util.deQuoteForSingleQuote(City)+"', zipcode='"+com.zoniac.util.Util.deQuoteForSingleQuote(Zipcode)+"', phonenumber1='"+com.zoniac.util.Util.deQuoteForSingleQuote(officePhone)+"', fax1='"+com.zoniac.util.Util.deQuoteForSingleQuote(Fax1)+"', email1='"+com.zoniac.util.Util.deQuoteForSingleQuote(email)+"', website='"+com.zoniac.util.Util.deQuoteForSingleQuote(WebSite)+"', description='"+com.zoniac.util.Util.deQuoteForSingleQuote(description)+"',timezoneid="+timeZone+", stateid="+stateId+" where companyid='"+companyid+"'");
if(rs != null) {
rs = null;
dbAccess.close();
}
}
%>
My customerDetail.jsp File
<%
String val = request.getParameter("val");
DBAccess dbAccess = Util.initDatabaseAccess();
ResultSet rs = null;
String outputResult = null;
String ff = "NO";
rs = dbAccess.executeQuery("select companyname,streetname1,streetname2,cityname,(select statename from state where stateid = (select stateid from yosemitecompany where companyid ="+val+"))as state,zipcode,phonenumber1,fax1,email1,website,description,companycode,companyid,(select stateid from state where stateid = (select stateid from yosemitecompany where companyid ="+val+"))as statecode,(select countryid from country where countryid =(select countryid from state where stateid = (select stateid from yosemitecompany where companyid ="+val+")))as countryid,timezoneid from yosemitecompany where companyid = "+val+"");
if(rs.next()){
outputResult = rs.getString(1)+"$"+rs.getString(2)+"$"+rs.getString(3)+"$"+rs.getString(4)+"$"+rs.getString(5)+"$"+rs.getString(6)+"$"+rs.getString(7)+"$"+rs.getString(8)+"$"+rs.getString(9)+"$"+rs.getString(10)+"$"+rs.getString(11)+"$"+rs.getString(12)+"$"+rs.getString(13)+"$"+rs.getString(14)+"$"+rs.getString(15)+"$"+rs.getString(16);
}
rs = null;
rs = dbAccess.executeQuery("select username,password from EMAILAUTHENTICATIONDETAILS where companyid="+val);
if(rs.next()){
ff="YES";
outputResult += "$"+rs.getString(1)+"$"+rs.getString(2);
}
if(ff.equals("NO")){
outputResult += "$$";
}
out.println(outputResult);
outputResult = null;
ff = "NO";
if(rs!=null) {
rs = null;
dbAccess.close();
}
%>