chinna
ajax+options is null or not an Object
2 Answer(s)      3 years and 7 months ago
Posted in : Ajax

HI i have developed a simple ajax application contains two drop down lists and and one search button when i seleted a mangername from the popuated dropdwon list its dispalyed all the employee names on selection of the employee name and i kept search it should dispalay me the employee details when i click on search button its saying options is null or not an Obejct..

here im sending my code

select.jsp

<%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showEmp(str){
      if (typeof XMLHttpRequest != "undefined"){
      xmlHttp= new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlHttp==null){
      alert("Browser does not support XMLHTTP Request")
      return;
      } 
      var url="getemp.jsp";
      url +="?managername="+str;
      alert(url);
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("empname").innerHTML=xmlHttp.responseText

      }   
      }


      function searchDetails(){
          var combo = document.getElementsByName("empname");
         //alert(combo.options[combo.selectedIndex].text);
          var str = combo.options[combo.selectedIndex].value;

          alert("val of str is "+str);
          if (typeof XMLHttpRequest != "undefined"){
              xmlHttp= new XMLHttpRequest();
              }
              else if (window.ActiveXObject){
              xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
              }
              if (xmlHttp==null){
              alert("Browser does not support XMLHTTP Request")
              return;

              } 

          var url="check.jsp";
          url +="?count="+str;
          alert(str);
          xmlHttp.onreadystatechange = stateChange1;
          xmlHttp.open("GET", url, true);
          xmlHttp.send(null);
          }

          function stateChange1(){   
          if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
           document.getElementById("data").innerHTML=xmlHttp.responseText


                          }   
          }

      </script>  
      </head>  
      <body>  
      Select ManagerName:<select name='managername' onchange="showEmp(this.value)">  
       <option value="none">SelectManagername</option>  

    <%
 Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from employee_table1");
 while(rs.next()){
     %>
      <option value="<%=rs.getString(3)%>"><%=rs.getString(3)%></option>  
      <%
 }
     %>
      </select>  

      <br>  
      <div id='empname'>  
      <select name='empname' >  
      <option value='-1'></option>  
      </select> 
           </div>  
       <input  type='button'   value= 'SearchforempDetails' onclick='searchDetails();' >
           <div id='data'>  
      <table name='data' >  
      </table>  
      </div>
      </body>
      </html>

getemp.jsp

<%@page import="java.sql.*"%>
<%
String managername=request.getParameter("managername");  
 String buffer="<select name='empname'><option value='-1'>SelectEmployeeName</option>";  
 try{
 Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from employee_table1 where managername='"+managername+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(2)+"'>"+rs.getString(2)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }

 %>

check.jsp

<%@page import="java.sql.*"%>
<%
String empname=request.getParameter("count");  
 String buffer="<table name='data'>";  
 try{
 Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from employee_table1 where empname='"+empname+"' ");  
   while(rs.next()){
   buffer=buffer+"<tr><td>"+rs.getString("empcode")+"</td><td>"+rs.getString("org")+"</td></tr>";  
 }  
 buffer=buffer+"</table>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }
  %>
   <%=empname%>

Database table table name employee_table1;

and empcode, empname, managername, org are columns

Pls help me

Thanks in Adavace

Advertisement
View Answers

November 4, 2011 at 12:03 PM


hi Thanks,

I figured out the solution










Related Tutorials/Questions & Answers:
ajax+options is null or not an Object
ajax+options is null or not an Object  HI i have developed a simple ajax application contains two drop down lists and and one search button when i... dispalay me the employee details when i click on search button its saying options
Null value when i set interface object in form controller - Spring
Null value when i set interface object in form controller   Hi all, i am very new about spring and hibernate. i got null value when i set interface object in form Controller. public void setOHBillManager(OHBillManager
Advertisements
null pointer
null pointer  dear sir , what is mean by null pointer in c
java.lang.NumberFormatException: null
java.lang.NumberFormatException: null   I get org.apache.jasper.JasperException: java.lang.NumberFormatException: null exception when i submit the form plz help me regarding
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
null interface
null interface   what is the null interface and what is the use of it in real java project ?   Hi Friend, A null interface is an interface without any methods.Is also known as Marker interface. Null interfaces are used
check null exception java
when we call or perform some action on the object or value when it null... if the object is null or assigned some value to it before performing action...check null exception java  check null exception java - How to check
Httpservletresponse null pointer exception.
Httpservletresponse null pointer exception.  What is Httpservletresponse null pointer exception?   NullPointerException occurs when we try to implement an application without referencing the object and allocating
Null Pointer Exception
Null Pointer Exception  whis is the Null Pointer Exception in java? or define Null Pointer Exception with exp?   NullPointerException occurs, when you try to implement an application without referencing the object
mysql query for null value
mysql query for null value   What mysql query for null value i need... { //echo message } To check if the object contain any value or not ..just compare it with zero. If the value for object is greater than zero display
javascript null mean
javascript null mean  What does javascript null mean
The null keyword
The null keyword       The null keyword in java programming language is a reserved word that is used... how to declare and define null values in java programming language
Null pointer execption
Null pointer execption  what is null pointer exception. I am getting the null pointer exception in this line conn= com.mypay.dao.Connection.getConnection(); what is wrong
Null pointer execption
Null pointer execption  what is null pointer exception. I am getting the null pointer exception in this line conn= com.mypay.dao.Connection.getConnection(); what is wrong
null pointer exception in java
null pointer exception in java  What is null pointer exception in Java and when it occurs? Show it with an example.Thanks!   Java Null Pointer Exception
Java null pointer exception
Java null pointer exception  Hi I've made an array of Book objects... and a short summary. A Book object also contains the appropriate constructor...]!=null){ if(strfield.contains(param)){ result+=library[counter
array_merge null - PHP
array_merge null   i am using the array_merge and getting the unusual null error...any help
disallow NULL values in a table.
disallow NULL values in a table.  How do I disallow NULL values in a table
What is NOT NULL Constraint?
What is NOT NULL Constraint?  What is NOT NULL Constraint?   Hi, The NOT NULL constraint enforces a column to NOT accept NULL values.The NOT NULL constraint enforces a field to always contain a value. This means
if variable is null php
if variable is null php  How to check if submitted variable is null in PHP? Thanks!   Check if Variable is NULL in PHP You can use isset($var) to check if the variable is not defined or null in PHP. and after setting
comparison with null - Framework
comparison with null  String value = txtfld.getText(); if (value == null) ----- failing step----control goes to else part { // some code... friend, if (value == null) works properly for comparision For any more
Output of null value
main(String [] args){ String str=null; System.out.println(str); } } Output value Null Description:- In the given example... a String variable and initialized it with null value
NULL POINTER EXCEPTION
NULL POINTER EXCEPTION    What is the Root cause for Class caste exception in struts frame work .and how 2 handle that 1 please help me
Stumped with NOT NULL AUTO_INCREMENT
Stumped with NOT NULL AUTO_INCREMENT  I've almost made it through my... to create a new table with the ID column being NOT NULL AUTO_INCREMENT. The table will create if I do not have NOT NULL AUTO_INCREMENT, but it WILL NOT create
array_merge null - PHP
array_merge null   i am using the array_merge and getting the unusual null error...any help?  Hi Friend, Please visit the following links: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Merge
comparison with null - Framework
comparison with null  I am having one textfield, from which I am getting text using getText() method. Now I want to compare this value with null (i.e. to check whether the entered value is null or not) How should I check
Server_Gives_Null_Response
Server_Gives_Null_Response   I have one InternetServer.java which starts a server at port 10000. In same class i have started a server at different...) to client class it always sends null and it shows NULL value only when i stop
Java null pointer exception handling
: java.lang.NullPointerException occurs when it tries to invoke a null object, at the time...Java null pointer exception handling   What... program? Is this extends from exception class of Java?   Java null
org.apache.jasper.JasperException: java.lang.NumberFormatException: null
: null" exception. Also "The server encountered an internal error... con=null; int mobile=Integer.parseInt(request.getParameter("mobile
NUll POINTER EXCEPTION
NUll POINTER EXCEPTION  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException... of code i m getting null pointer Exception. can some one please explain what
Null pointer exception in hibernate - Hibernate
Null pointer exception in hibernate  Hi i am getting null pointer... is compiled successfully but while running the program i am getting null ponter exception. SessionFactory object is not creating pls give me the solution