Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 870227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:26:13+00:00 2026-05-15T10:26:13+00:00

I am working on the jsp/servlet/ajax application. I use XMLHttpRequest to pass values from

  • 0

I am working on the jsp/servlet/ajax application.
I use XMLHttpRequest to pass values from the JSP page to servlet, which retrieve data from the database and returns XML to the JSP.

The code works but there is one thing I do not understand.
Here is a JSP part

<body>
    <label>Longitude</label><input type="text" id ="lat" value="40.799559" />
    <br/>
    <label>Latitude</label><input type="text" id="lon" value="-74.481386" />
    <br/><br/>
    <input type="button" onclick="checkGPSCoords(document)" value="Test" />
    <br/><br/>
    <input type="text" id ="dbCounty" readonly/>
    <br/>
    <input type="text" id ="dbMuni" readonly />
    <br/><br/>
</body>

I am passing a document element into the JavaScript
Here is a script:

<script type="text/javascript" language="JavaScript">
    var req;
    var isIE;
    function initRequest() {
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            isIE = true;
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function checkGPSCoords(currentWindow){
        var lat= currentWindow.getElementById("lat").value;
        var lon = document.getElementById("lon").value;
        //alert("lon:" + lon);
        initRequest();
        req.open("GET","./lonlat?lat="+ lat + "&lon=" + lon);
        req.onreadystatechange = retrieveMuniCntyNames;
        req.send(null);
    }

    function retrieveMuniCntyNames() {
        var muniAndCnty;

        if (req.readyState==4) {
            if(req.status==200) {
                var XMLresult = req.responseXML;
                muniAndCnty = XMLresult.getElementsByTagName("rec");

                //incoming from Servlet  <twp><rec twp='Morristown town' cnty='Morris' /></twp>
                var c = document.getElementById("dbCounty");
                var t = document.getElementById("dbMuni")
                c.setAttribute("value",muniAndCnty[0].getAttribute("cnty") )
                t.setAttribute("value",muniAndCnty[0].getAttribute("municipality") )                        
            }
        }
    }
</script>

Function checkGPSCoords knows a document name (which is my JSP file name).
What I puzzle me that callback function retrieveMuniCntyNames() also knows the name of the document since it sets attributes to input elements on the JSP without error.
I checked it the firebug.

I would appreciate any thoughts on the subject.
Thanks,
Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:26:14+00:00Added an answer on May 15, 2026 at 10:26 am

    I’m unsure what setup you’re trying to convey here, or where the javascript would be in the code. I’m making the assumption here that you’ve defined the script in the same page or you’re including it from an external file.

    Nonetheless, when the javascript executes, the browser isn’t leaving the page. Therefore, the document doesn’t change. From the code you’ve provided, you’re not attempting to open a new window or navigate away from the page. Therefore the document variable hasn’t changed from one function call to another, even after a successful AJAX call. It’s the same document before, during, and after the AJAX call.

    By that same token, you can probably eliminate the currentWindow parameter from your checkGPSCoords function. You’re not really checking a window object since you’re passing a document object to the function. Also, the window object doesn’t have a getElementById method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a java web-application, trying to be xml-friendly and writing my jsp
I need to get UTF-8 working in my Java webapp (servlets + JSP, no
I'm working on a JSP where I need to call methods on object that
Working on a somewhat complex page for configuring customers at work. The setup is
Working with python interactively, it's sometimes necessary to display a result which is some
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project at the moment and we have to implement soft deletion
Working on a project that parses a log of events, and then updates a
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.