views:

26

answers:

1

Right now I have a loop that is going up by one until it hits its page limit. (this is a mini book/magazine)

I have them inserted into a drop down so a user could select the number they want and it will jump to that page.

Is there any way to instead of use numbers, somehow get titles into it instead? Like Front cover, table of contents, Toyota ad, etc?

Could I somehow list off what I would want to be displayed in a separate text file, and have the loop go through each title and display it instead of numbers?

Thanks for any help :) I am only using jquery & javascript... and html of course.

+1  A: 

Instead of using a counter, you can create an object/array that would resemble a table of contents. Do something like this:

var pages = {
   0 : 'Title Page',
   1 : 'Table of Contents',
   2 : 'Chapter One',
   3 : 'Chapter Two',
   5 : 'Chapter Three'
};

or more simply:

var pages = [
   'Title Page',
   'Table of Contents',
   'Chapter One',
   'Chapter Two'
];

Then your code could be something like this:

$.each(pages, function(index, value) {
    $(document.createElement('option')).val(index).text(value).appendTo($('select#id-here'));
}
js1568