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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:42:57+00:00 2026-05-13T23:42:57+00:00

I have a simple array with x number of items. I am displaying them

  • 0

I have a simple array with x number of items. I am displaying them individually via a link click… I want to update a number that say 1 of 10. when the next one is displayed i want it to display 2 of 10 etc…

I have looked all around and my brain is fried right now… I know its simple I just cant get it out.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <title>Page Title</title>
   <link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8"/>
   <script type="text/javascript">
    var quotations = new Array()
        quotations[0]= "abcd"
        quotations[1]= "efgh"
        quotations[2]= "ijkl"
        quotations[3]= "mnop"
        quotations[4]= "qrst"
        quotations[5]= "uvwx"
        quotations[6]= "yzab"

        numQuotes = quotations.length;
        curQuote = 1;

        function move( xflip ) {
        curQuote = curQuote + xflip;
        if (curQuote > numQuotes)
        { curQuote = 1 ; }
        if (curQuote == 0)
        { curQuote = numQuotes ; }
        document.getElementById('quotation').innerHTML=quotations[curQuote - 1];
        }
        var curPage = curQuote
               </script>

</head>

<body>
<div id="quotation">
<script type="text/javascript">document.write(quotations[0]);</script>
</div>
<div>
<p><a href="javascript();" onclick="move(-1)">GO back</a>
<script type="text/javascript">document.write(curPage + " of " + numQuotes)</script>
<a href="javascript();" onclick="move(1)">GO FORTH</a></p>

</div>
</body>

</html>

Edit: curQuote is not updating dynamically… it stays at ‘1’ when next is clicked.

  • 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-13T23:42:57+00:00Added an answer on May 13, 2026 at 11:42 pm

    In your code, curQuote is already the value you want. I rewrote everything to clean it up and show some better logic/syntax. Note that ideally you would be attaching the click handlers via DOM methods and not using inline handlers, but for simplicity I’ve left it that way here.

    Working version viewable here: http://jsbin.com/irihu3/2

    <html>
      <head>
        <title>Quotations</title>
        <script type="text/javascript" charset="utf-8">
          var quotations = ["hi", "how", "are", "you", "today", "good", "sir"],
            lastIndex = quotations.length - 1,
            currentIndex = 0;
    
          function move(xflip) {
            currentIndex = currentIndex + xflip;
    
            if (currentIndex > lastIndex) {
              currentIndex = 0;
            } else if (currentIndex < 0) {
              currentIndex = lastIndex;
            }
    
            document.getElementById('quotation').innerHTML = quotations[currentIndex] + " (Quote #" + (currentIndex + 1) + ")";
            return false;
          }
        </script>
      </head>
      <body>
        <div id="quotation">hi (Quote #1)</div>
        <a onclick="move(-1);">Prev</a>
        <a onclick="move(1)">Next</a>
      </body>
    </html>
    

    Some things to note:

    • Always declare variables with the var keyword or you create global variables.
    • You can combine multiple variable declarations into one statement by separating them with commas. It’s good practice to stick to one var statement and to put it at the top of your code/function.
    • All you really need to keep track of here is the current index of the array, not the quote itself. It’s also not important how long the array is, just what the last index is. As such, in my code I am using currentIndex and lastIndex instead of curQuote and numQuotes.
    • Using return false; at the end of your function will suppress the default action when clicking on a hyperlink (not following the link). This is what you want in this case, because you’re using a hyperlink to trigger behavior on the page and not actually navigating to another page.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty simple scenario. I have a web service that receives a byte array that
I have a simple 2D array of strings and I would like to stuff
I have a simple function in which an array is declared with size depending
Should simple JavaBeans that have only simple getters and setters be unit tested?? What
I have a simple webform that will allow unauthenticated users to input their information,
I have a simple 2-column layout with a footer that clears both the right
I have a simple program that lets you add, edit, list, search and delete
I'm confused, I have @quote.quote_line_items and this is an array of items like this:
Hi I have a simple ajax search that returns the results in a table.
I have simple regex \.*\ for me its says select everything between and ,

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.