473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
7 3894
gits
5,390 Expert Mod 4TB
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
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
608 512MB
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
16,027 Expert Mod 8TB
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
16,027 Expert Mod 8TB
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
608 512MB
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
16,027 Expert Mod 8TB
Thank you for the correction acoder
Not necessarily a correction - more improvements/alternatives.
Mar 24 '08 #8

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

Similar topics

2
by: Dave Hammond | last post by:
I've got what should be a simple assignment of either an element value or a default string to a variable, but when the element doesn't exist I get an "Object required" error rather than an...
53
by: Aaron Gray | last post by:
I jokingly say this is the late entry :) Okay I have read all the event entry comments from John's Resig's AddEvent comepition blog :- http://ejohn.org/projects/flexible-javascript-events/ ...
19
by: bonneylake | last post by:
Hey Everyone, Well i keep getting the error that addInput is not defined but i can not figure out what is wrong with it. It worked perfectly fine when i was using it to submit data. But now that i...
1
by: DelphiCoder | last post by:
I'm trying to simulate buttons using images. I tried many ways and I don't seem to get it to work as far as the button label is concerned. I tried manipulating "top" and "left" and now the margins...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.