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

  • SEARCH
  • Home
  • 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 8583319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:30:24+00:00 2026-06-11T21:30:24+00:00

I’m working on a postcode (airports & train station) search but can’t seem to

  • 0

I’m working on a postcode (airports & train station) search but can’t seem to figure out why the selected row values are not writing the correct values to the hidden text boxes.

Basically if I search ‘Gatwick’ as shown below:

enter image description here

I get the following XML response:

<?xml version="1.0"?>
<addresslist resultcount="4">
    <address id="0" catagoryid="1" lat="184179968" lng="-639296">
        <companyname></companyname>
        <premiseno></premiseno>
        <streetname>GATWICK AIRPORT (NORTH)</streetname>
        <townname></townname>
        <postcode>RH6 0PJ</postcode>
    </address>
    <address id="1" catagoryid="1" lat="184161536" lng="-586944">
        <companyname></companyname>
        <premiseno></premiseno>
        <streetname>GATWICK AIRPORT (SOUTH)</streetname>
        <townname></townname>
        <postcode>RH6 0NP</postcode>
    </address>
    <address id="2" catagoryid="1" lat="184161664" lng="-580224">
        <companyname></companyname>
        <premiseno></premiseno>
        <streetname>GATWICK GATWICK AIRPORT RAILWAY STATION</streetname>
        <townname></townname>
        <postcode>RH6 0RD</postcode>
    </address>
    <address id="3" catagoryid="1" lat="184161536" lng="-586944">
        <companyname></companyname>
        <premiseno></premiseno>
        <streetname>GATWICK RAILWAY CONCOURSE</streetname>
        <townname></townname>
        <postcode>RH6 0NN</postcode>
    </address>
</addresslist>

At the moment, no matter which row I select, it always writes the last Lat & Long values to the hidden textbox. For example, If i select the first row, it will write 184161536, -586944 which is the Lat Long values for ‘GATWICK RAILWAY CONCOURSE’

Here is the Jquery Code:

function buildResultView(xml_object,pageNum,rowdiv) {

// Remove existing page up page down click events
rowdiv.find('.lbl-addr-pgup').unbind('click');
rowdiv.find('.lbl-addr-pgdn').unbind('click');

// Remove result list if there is one
if (rowdiv.find('.ul-result-view')) {
    rowdiv.find('.ul-result-view').remove();
}

ul = $('<ul></ul>');
ul.addClass('ul-addr-res');
ul.addClass('ul-result-view');

// Prepend ul before resultinfo
rowdiv.find('.div-result-info').before(ul); 

// Reset result count
var resCount = 0;

// Count Results
$(xml_object).find('address').each(function(){
    resCount += 1;
});

// Pull out start row and max rows
var pageRes = clientPaginate(resCount,pageNum).split(',');
var loopMax = parseInt(pageRes[0]);
var currentRow = parseInt(pageRes[1]);
var lastPge = parseInt(pageRes[2]);
var addType;

// Show maxRows starting at startIndex  
for (var i = currentRow; i < loopMax; i++) {

    var li = $('<li></li>');
    li.addClass('li-addr-res');
    addType = parseInt($(xml_object).find("address[id='"+i+"']").attr("catagoryid"));
    var lat = ($(xml_object).find("address[id='"+i+"']").attr("lat"));
    var lng = ($(xml_object).find("address[id='"+i+"']").attr("lng"));

    li.css('cursor','pointer');

// Reset result count
var resCount = 0;

// Count Results
$(xml_object).find('address').each(function(){
    resCount += 1;
});

// Pull out start row and max rows
var pageRes = clientPaginate(resCount,pageNum).split(',');
var loopMax = parseInt(pageRes[0]);
var currentRow = parseInt(pageRes[1]);
var lastPge = parseInt(pageRes[2]);
var addType;

// Show maxRows starting at startIndex  
for (var i = currentRow; i < loopMax; i++) {

    var li = $('<li></li>');
    li.addClass('li-addr-res');
    addType = parseInt($(xml_object).find("address[id='"+i+"']").attr("catagoryid"));
    var lat = ($(xml_object).find("address[id='"+i+"']").attr("lat"));
    var lng = ($(xml_object).find("address[id='"+i+"']").attr("lng"));

Then I write the lat, lng values to the hidden textbox:

    // Add this lat lng to hidden text box
    rowdiv.find('.hidden-lat-lng').val(lat+","+lng);

Any idea why this isn’t selected the correct latitude longtitude values?

I just need to be able to get the latitude longtitude values of the row that is selected.

If anybody could help with this, I would be very greatful! 🙂

  • 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-06-11T21:30:26+00:00Added an answer on June 11, 2026 at 9:30 pm

    When you have code like this:

    for (var i = 0; i < 10; i++) {
       var foo = i;
    }
    

    foo is going to be 9. That’s what’s happening, your lat and lng values are simply the last ones in the loop, because that’s where you’re setting them.

    Note that it doesn’t matter whether you declare foo inside the for() loop or outside it; variable scope in javascript is not block-level like it is in many other languages and using var will give these ones the scope of the function.

    You’re trying to redeclare variables as well; I’m not sure whether that’s just a result of copy-pasting the code or a misunderstanding of variable scope but in any case it will have no subsequent effect. It would be clearer and probably lead to fewer gotchas if you just declare your local variables at the top of the function.

    There is presumably more code dealing with which row is selected. If it sets lat and lng then post it to your question. Otherwise, here’s my take:

    for (var i = currentRow; i < loopMax; i++) {
        var li = $('<li></li>');
        li.addClass('li-addr-res');
        addType = parseInt($(xml_object).find("address[id='"+i+"']").attr("catagoryid"));
    
        lat = ($(xml_object).find("address[id='"+i+"']").attr("lat"));
        lng = ($(xml_object).find("address[id='"+i+"']").attr("lng"));
    
        // Store the latitude and longitude alongside the li element itself
        li.data('lat', lat).data('lng', lng);
    
        // add a handler to copy that data to the hidden textarea when clicked
        // I'm assuming you mean the row is selected when it's clicked, otherwise
        // just bind to something else
        li.click(function() {        
            // recover the data from this element (the <li>)
            var lat = $(this).data('lat'),
                lng = $(this).data('lng');
    
            // rowdiv is probably still in scope from the parent function,
            // though there is missing code in your question. I'm going to 
            // assume there's only one hidden textarea for this purpose
            $('.hidden-lat-lng').val(lat + "," + lng);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.