Returning currently displayed index of an array Javascript...

Posted by Jeff Kindred on Stack Overflow See other posts from Stack Overflow or by Jeff Kindred
Published on 2010-03-12T20:22:13Z Indexed on 2010/03/12 20:47 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

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]= "1"
        quotations[1]= "2"
        quotations[2]= "3"
        quotations[3]= "4"
        quotations[4]= "5"
        quotations[5]= "6"
        quotations[6]= "7"

        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 = //this is where the current index should go
               </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>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about newbie