By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

getElementById("results").innerHTML = message has no properties

P: 2
Hello,

I have been having this problem for the whole day today, so even after i googled for the solution i was not able to get one, so i had to post to this forum. I had checked the solutions suggested on this forum but its not working for me still.

Ok I would start from the beginning:


Plastform:
---------------
MAC OS X 10.5.2
Netbeans IDE 6.0.1
Glassfish V2UR1
MySQL 5.0
Firefox


Code:

1> I have an enterprise application in the NetBeans and basically i am trying to create a web 2.0 based project in which the user when he/she inputs the username they are immediately informed if the userid is available or not.

JSP code:
---------------
Expand|Select|Wrap|Line Numbers
  1. <%-- 
  2.     Document   : UserSignOn
  3.     Created on : Mar 13, 2008, 4:07:08 PM
  4.     Author     : ankittoshniwal
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8.  
  9.  
  10.  
  11. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  12. "http://www.w3.org/TR/html4/loose.dtd">
  13.  
  14. <html>
  15.     <head>
  16.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  17.         <title>User Sign On</title>
  18.         <script language="javascript">
  19.             var xmlHttp; 
  20.  
  21.             function createXmlHttpRequest() 
  22.             {
  23.                 try
  24.                 {
  25.                     xmlHttp = new XMLHttpRequest();
  26.  
  27.                 } catch (tryMicrosoft)
  28.                 {
  29.                     try {
  30.                         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  31.                     }
  32.                     catch (otherMicrosoft)
  33.                     {
  34.                         try
  35.                         {
  36.                             request = new ActiveXObject("Microsoft.XMLHTTP");
  37.                         }catch (failed)
  38.                         {
  39.                             xmlHttp = false;
  40.                         }
  41.                     }
  42.                 }
  43.  
  44.                 if (!xmlHttp)
  45.                     alert("error initializing XMlHttpRequest");
  46.             }
  47.             function callServer() 
  48.             {
  49.  
  50.                 createXmlHttpRequest();
  51.                 // var nameValue = document.getElementById("n");
  52.                 var userNameValue = document.getElementsByName("user").value;
  53.  
  54.                 var url = "/TestProject-war/data?tempUserName=" + escape(userNameValue);
  55.  
  56.                 xmlHttp.open("GET", url, true);
  57.  
  58.                 xmlHttp.onreadystatechange = confirmUpdate;
  59.  
  60.                 xmlHttp.send(null);
  61.  
  62.             }
  63.  
  64.             function confirmUpdate() 
  65.             {
  66.  
  67.                 if (xmlHttp.readyState == 4)
  68.                     {
  69.                         if (xmlHttp.status == 200)
  70.                             {
  71.  
  72.                                 var message =  
  73.                                 xmlHttp.responseXML
  74.                                 .getElementsByTagName("valid")[0]
  75.                                 .childNodes[0].nodeValue;
  76.  
  77. // Basically this is the point which is giving me errors
  78.                  document.getElementById("results").innerHTML = message;
  79.  
  80.                             }
  81.                             else
  82.                                 {
  83.                                     alert("Error loading page" + xmlHttp.status );
  84.                                 }
  85.                             }
  86.  
  87.  
  88.                         }
  89.         </script>
  90.  
  91.     </head>
  92.     <body>
  93.  
  94.         <p> We are trying to read</p>
  95.         <input type="text" onkeyup="callServer();"/>
  96.          <td width="31%" id=”results”>&nbsp;</td>
  97.  
  98.     </body>
  99. </html>
  100.  
Servlet Code:
--------------------
So what i was planning to do was get the input from the JSP page and transfer it to the Servlet. In the servlet i was trying to connect to database and get the username approved, but i was getting the same errors, and hence i deleted the whole code and i just wrote a simple code in which whatever might be the input by the user in the JSP page the servlet would return "true" from the servlet meaning the username is true and available.

Code is as follows:
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package org.web;
  7.  
  8. import java.io.*;
  9. import java.net.*;
  10. import java.math.*;
  11.  
  12. import java.util.List;
  13. import java.util.ListIterator;
  14. import javax.ejb.EJB;
  15. import javax.servlet.*;
  16. import javax.servlet.http.*;
  17. import org.ejb.UserDetailsFacadeLocal;
  18. import org.ejb.UserDetails;
  19.  
  20. /**
  21.  *
  22.  * @author ankittoshniwal
  23.  */
  24. public class data extends HttpServlet {
  25.     @EJB
  26.     private UserDetailsFacadeLocal userDetailsFacade;
  27.  
  28.    String tempUsr;
  29.    String tempUsername;
  30.    String tempId;
  31.     /** 
  32.     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  33.     * @param request servlet request
  34.     * @param response servlet response
  35.     */
  36.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  37.     throws ServletException, IOException {
  38.         response.setContentType("text/html;charset=UTF-8");
  39.         PrintWriter out = response.getWriter();
  40.         try {
  41.             // TODO output your page here
  42.             out.println("<html>");
  43.             out.println("<head>");
  44.             out.println("<title>Servlet data</title>");  
  45.             out.println("</head>");
  46.             out.println("<body>");
  47.             out.println("<h1>Servlet data at " + request.getContextPath () + "</h1>");
  48.             UserDetails UserDetailsObj = new UserDetails();
  49.             out.println("</body>");
  50.             out.println("</html>");
  51.  
  52.         } finally { 
  53.             out.close();
  54.         }
  55.     } 
  56.  
  57.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  58.     /** 
  59.     * Handles the HTTP <code>GET</code> method.
  60.     * @param request servlet request
  61.     * @param response servlet response
  62.     */
  63.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  64.     throws ServletException, IOException {
  65.  
  66.         PrintWriter out = response.getWriter();
  67.         UserDetails userObj = new UserDetails();
  68.      //   String checkName = request.getParameter("name");
  69.       //  String checkUserName = request.getParameter("user");
  70.        // String temp;
  71.  
  72.                     response.setContentType("application/xml");
  73.                     response.setHeader("Cache-Control", "no-cache");
  74.                     response.getWriter().write("<valid>true</valid>");
  75.     } 
  76.  
  77.     /** 
  78.     * Handles the HTTP <code>POST</code> method.
  79.     * @param request servlet request
  80.     * @param response servlet response
  81.     */
  82.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  83.     throws ServletException, IOException {
  84.  
  85.         PrintWriter out = response.getWriter();
  86.  
  87.               doGet(request, response);  
  88.        // processRequest(request, response);
  89.     }
  90.  
  91.     /** 
  92.     * Returns a short description of the servlet.
  93.     */
  94.     public String getServletInfo() {
  95.         return "Short description";
  96.     }
  97.     // </editor-fold>
  98. }
----------------------------------------------------------------------

can somebody explain me where i am going wrong, i have been following the IBM's AJAX tutorial but its not helping out.

Any help would be greatly appreciated.

Thanks,
Ankit.
Mar 20 '08 #1
Share this Question
Share on Google+
7 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

could you first try to fix the quotes in your line 96 ... that seems to be strange quotes ...

if that doesn't help next step: could you alert the message-text instead of setting innerHTML? is the alert showing you what you would expect?

kind regards
Mar 20 '08 #2

P: 2
Hi,

Thanks for the reply.

I did try what you had asked me to, i changed the quotes and now they are,

document.getElementById("results").innerHTML = message;

also when i just alert the message-text i do get the required output but it just wont show it when i pass the command given above.

Thanks,
Ankit.
Mar 21 '08 #3

RamananKalirajan
100+
P: 607
Hi,

Thanks for the reply.

I did try what you had asked me to, i changed the quotes and now they are,

document.getElementById("results").innerHTML = message;

also when i just alert the message-text i do get the required output but it just wont show it when i pass the command given above.

Thanks,
Ankit.
Hello Mr. Ankit, it's a suggestion, why can't you try like this
[HTML]
<td><span Id="results"></span></td><br/>[/HTML]

Just try whether it is working or not

Regards
Ramanan Kalirajan
Mar 21 '08 #4

acoder
Expert Mod 15k+
P: 16,027
I did try what you had asked me to, i changed the quotes and now they are,

document.getElementById("results").innerHTML = message;

also when i just alert the message-text i do get the required output but it just wont show it when i pass the command given above.
Strange that you have a td element without a table tag. Perhaps if you enclose it within a table, it could work.
Mar 22 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Hello Mr. Ankit, it's a suggestion, why can't you try like this
[HTML]
<td><span Id="results"></span></td><br/>[/HTML]

Just try whether it is working or not
or even without the td element, i.e. just the span element, or a div element. I think that the "Id" should be lowercase, i.e. id="results".
Mar 22 '08 #6

RamananKalirajan
100+
P: 607
or even without the td element, i.e. just the span element, or a div element. I think that the "Id" should be lowercase, i.e. id="results".
Thank you for the correction acoder

Regards
Ramanan kalirajan
Mar 24 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Thank you for the correction acoder
Not necessarily a correction - more improvements/alternatives.
Mar 24 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.