Wrox Programmer Forums
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2003, 02:10 PM
Registered User
 
Join Date: Jun 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to menesesg
Default switch and arrays

Hello there:

I have an array where i have listed all the .htm´s in my project, right now I acces them through the position number inside the array with a var Position, this works fine but in the future the number of htm´s will increase so all the positions will move. I want to know how I can get the "name" of the htm, instead of the position through a "switch" method:

My code now is:

var laPosicion = 0;
if(laPosicion == 0) {
laPosicion = 0; } //else { laPosicion--; }

    switch(laPosicion){
    case 0:
        window.top.mainFrame.laPosicion=0
        break;
         etc,.........
          }

thanks a lot in advance
 
Old July 3rd, 2003, 01:55 PM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lillu
Default

Hi,

By simply referencing the index number of the elements in an array, you'll get their content and not their position in the array.

Eg.

<html>
<body>
<script language="javascript">

var myProjects = new Array("index.htm","01.htm","02.htm","03.htm","04.h tm");

switch (n)
{
case 0:
    document.write(myProjects[0]);
    break;
case 1:
    document.write(myProjects[1]);
    break;
case 2:
    document.write(myProjects[2]);
    break;
case 3:
    document.write(myProjects[3]);
    break;
case 4:
    document.write(myProjects[4]);
    break;
default:
    break;
}

</script>
</body>
</html>

HTH,

Lillu

The Purple Couch
http://www.geocities.com/lillamarta





Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch mamatharocks Biztalk 0 May 22nd, 2008 11:29 PM
if or switch Dink Classic ASP Databases 2 February 4th, 2007 04:00 AM
Switch rajuru Beginning PHP 2 February 9th, 2005 11:24 AM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.