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 918771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:25:55+00:00 2026-05-15T18:25:55+00:00

I created a google maps store locator and im using a jquery pagination to

  • 0

I created a google maps store locator and im using a jquery pagination to show only 5 results per page. It works. The only problem is that every time I hit search it duplicates the pagination.

Screen shot 2010-07-05 at 11.54.13 AM.png

Code:

function paginate(){
var page = 1;
var itemsPerPage = 4;
var prev = "Previous Results";
var next = "More Results";

var $entries = $("#entries");
var $list = $entries.children("ul:first");
$list.children().eq(itemsPerPage).nextAll().andSelf().hide();

var $pagination = $("<ul class='pagination'></ul>").each(function () {
   var itemsTotal = $list.children().size();
   var pages = Math.ceil(itemsTotal / itemsPerPage);
$(this).append("<span class='endline'></span>");
   $(this).append("<li class='prev'>" + prev + "</li>");
   $(this).append("<li class='more'>" + next + "</li>");
}).appendTo($entries);
$pagination.children("li:first").hide();
$pagination.children().click(function () {

   if ($(this).text() == prev)
       page = page - 1;
   else if ($(this).text() == next)
       page = page + 1;

   var firstToShow = (page - 1) * itemsPerPage;
   var lastToShow = page * itemsPerPage;
   $list.children().hide().slice(firstToShow, lastToShow).slideDown('slow');

   if (page == 1)
       $(this).parent().find("li:first").hide();
   else
       $(this).parent().find("li:first").show();
   if (page == Math.ceil($list.children().size() / itemsPerPage))
       $(this).parent().find("li:last").hide();
   else
       $(this).parent().find("li:last").show();
});
}

And then in the google maps javascript I have (code is taken from Creating a Store Locator with PHP, MySQL & Google Maps):

function searchLocationsNear(center) {
var radius = document.getElementById('radiusSelect').value;
var searchUrl = 'genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
GDownloadUrl(searchUrl, function(data) {
 var xml = GXml.parse(data);
 var markers = xml.documentElement.getElementsByTagName('marker');
 map.clearOverlays();

 var sidebar = document.getElementById('sidebar');
 sidebar.innerHTML = '';
 if (markers.length == 0) {
   sidebar.innerHTML = '<p class="caption">No results found.</p>';
   map.setCenter(new GLatLng(40, -100), 4);
   return;
 }

 var bounds = new GLatLngBounds();
 for (var i = 0; i < markers.length; i++) {
   var name = markers[i].getAttribute('name');
   var address = markers[i].getAttribute('address');
   var type = markers[i].getAttribute('type');
   var distance = parseFloat(markers[i].getAttribute('distance'));
   var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                           parseFloat(markers[i].getAttribute('lng')));

   var marker = createMarker(point, name, address, type);
   map.addOverlay(marker);
   var sidebarEntry = createSidebarEntry(marker, name, address, distance, type);
   sidebar.appendChild(sidebarEntry);
   bounds.extend(point);
 }
paginate();
results();
  map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
 });
     }

html:

<div id="entries">
<ul id="sidebar">
   <li>all the entries</li>
   <li>all the entries</li>
   ...etc
</ul>
and then the pagination
<ul class="pagination"></ul>
</div>

and on the button there is:

<input type="button" onclick="searchLocations()" class="submit" value="Search"/>

and that function is:

function searchLocations() {
var address = document.getElementById('addressInput').value;
geocoder.getLatLng(address, function(latlng) {
if (!latlng) {
sidebar.innerHTML = '<p class="caption"><b>No results found.</b><br><br>Please try your search again. Make sure to enter a single city, state, or zip code.</p>';
 } else {
   searchLocationsNear(latlng);
   filter();
 }
});
}
  • 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-15T18:25:56+00:00Added an answer on May 15, 2026 at 6:25 pm

    Add the following line to remove any existing pagination before it is re-created in the paginate() function:

    $(".pagination").remove();
    

    So you end up with:

    $(".pagination").remove();
    var $pagination = $("<ul class='pagination'></ul>").each(function () { 
       ...
    }).appendTo($entries); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.