From: Pukeko on
Hi, this is an array that is used for a dropdown menu.

var imageArray = new Array(
"ecwp://" + document.location.host + "/massey/images/massey/
massey_07_fullres.ecw",
"ecwp://" + document.location.host + "/sampleiws/images/usa/
1metercalif.ecw",
"ecwp://" + document.location.host + "/sampleiws/images/australia/
parramatta.ecw";

when the menu is displayed it shows the whole value

"ecwp://" + document.location.host + "/massey/images/massey/
massey_07_fullres.ecw""

is there a way i can just display a name for the image in the dropdown
menu, like "Massey 2007"

cheers
From: "Tim Williams" timjwilliams at gmail dot on

"Pukeko" <pukeko.taniwha(a)gmail.com> wrote in message
news:eab0f478-cfc2-483f-b888-e095d4c2dbee(a)i36g2000prf.googlegroups.com...
> Hi, this is an array that is used for a dropdown menu.
>
> var imageArray = new Array(
> "ecwp://" + document.location.host + "/massey/images/massey/
> massey_07_fullres.ecw",
> "ecwp://" + document.location.host + "/sampleiws/images/usa/
> 1metercalif.ecw",
> "ecwp://" + document.location.host + "/sampleiws/images/australia/
> parramatta.ecw";
>
> when the menu is displayed it shows the whole value
>
> "ecwp://" + document.location.host + "/massey/images/massey/
> massey_07_fullres.ecw""
>
> is there a way i can just display a name for the image in the dropdown
> menu, like "Massey 2007"
>
> cheers

How are you building the menu ? If you have code to do that (and it's
always useful to include that in your post), then just adjust to suit.

Otherwise, you haven't provided enough information to answer your queston.

Tim


From: Tom Cole on
On May 5, 2:24 am, "Tim Williams" <timjwilliams at gmail dot com>
wrote:
> "Pukeko" <pukeko.tani...(a)gmail.com> wrote in message
>
> news:eab0f478-cfc2-483f-b888-e095d4c2dbee(a)i36g2000prf.googlegroups.com...
>
>
>
>
>
> > Hi, this is an array that is used for a dropdown menu.
>
> > var imageArray = new Array(
> > "ecwp://" + document.location.host + "/massey/images/massey/
> > massey_07_fullres.ecw",
> > "ecwp://" + document.location.host + "/sampleiws/images/usa/
> > 1metercalif.ecw",
> > "ecwp://" + document.location.host + "/sampleiws/images/australia/
> > parramatta.ecw";
>
> > when the menu is displayed it shows the whole value
>
> > "ecwp://" + document.location.host + "/massey/images/massey/
> > massey_07_fullres.ecw""
>
> > is there a way i can just display a name for the image in the dropdown
> > menu, like "Massey 2007"
>
> > cheers
>
> How are you building the menu ?  If you have code to do that (and it's
> always useful to include that in your post), then just adjust to suit.
>
> Otherwise, you haven't provided enough information to answer your queston.
>
> Tim- Hide quoted text -
>
> - Show quoted text -

Javascript arrays are a little tricky in this regards. Yes you can
"name" and Array entry, or more accurately assign a "name" as the key.
The problem is, in my experience, that when store array elements in
this manner, the length of the array is not adjusted. For example this
is totally legit:

var images = new Array();
images['Massey 2007'] = "ecwp://" + document.location.host + "/massey/
images/massey/massey_07_fullres.ecw";
images['Massey 2006'] = "ecwp://" + document.location.host + "/massey/
images/massey/massey_06_fullres.ecw";

However if you call alert(images.length) you will get 0. Of course
even if it didn't, this wouldn't help, because you need the key (or
"name") not just the value. And there is no method that I have found
to retrieve the list of keys an array is using. So...the problem isn't
"naming" your array elements, but how do you remember that list of
names so you can later retrieve the values.

You will probably need two arrays, one to store the "names" and the
other to store the "values". How you arrange to coordinate the two are
up to you. You could simply ensure that both arrays are the same
length and that the element 0 in the names array correlates to the
element 0 in the values array, or you could keep the names in array 1
and use the names as the keys in array 2. For example:

var names = new Array();
var urls = new Array();

names.push("Massey 2007");
urls["Massey 2007"] = "ecwp://" + document.location.host + "/massey/
images/massey/massey_07_fullres.ecw";

Then you could loop through the names array and pull the url using
that value as the key from the second array. For example:

for (var i = 0; i < names.length; i++) {
var name = names[i];
var url = urls[name];
//build your Option here...

}

HTH...
From: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= on
Tom Cole <tcole6(a)gmail.com> wrote:

>
> var names = new Array();
> var urls = new Array();

it is easier to use an object :

var myObject={};
myObject[name_1]=url_1;
....
myObject[name_n]=url_n;


that way, unless u've added properties to Object, using
Object.prototype, u can get all the key/value pair by

for(var key in myObject{
alert("key = "+key+", value = "+value);
}
--
Une B�vue
From: Thomas 'PointedEars' Lahn on
Pukeko wrote:
> Hi, this is an array that is used for a dropdown menu.

From your question below I surmise you are probably talking about a `select'
element that only works with present and enabled client-side script support,
which would be a really bad idea.

> var imageArray = new Array(
> "ecwp://" + document.location.host + "/massey/images/massey/
> massey_07_fullres.ecw",

document.location has been deprecated more than 10 years ago.

> "ecwp://" + document.location.host + "/sampleiws/images/usa/
> 1metercalif.ecw",
> "ecwp://" + document.location.host + "/sampleiws/images/australia/
> parramatta.ecw";

Your source code is syntactically incorrect: the closing `)' for the
constructor call is missing. That aside, I would do at least:

var imageArray = new Array(
new Array("ecwp://", "/massey/images/massey/massey_07_fullres.ecw"),
new Array("ecwp://", "/sampleiws/images/usa/1metercalif.ecw"),
new Array("ecwp://", "/sampleiws/images/australia/parramatta.ecw")
);

for (var i = 0, len = imageArray.length; i < len; i++)
{
imageArray[i] = imageArray[i].join(document.location.host);
}

> when the menu is displayed it shows the whole value
>
> "ecwp://" + document.location.host + "/massey/images/massey/
> massey_07_fullres.ecw""
>
> is there a way i can just display a name for the image in the dropdown
> menu, like "Massey 2007"

Yes, there is, for example by using your own constructor:

/**
* Constructs a new <code>Item</code> object.
*
* @param uriParts: Array
* 2-element array containing the scheme and the path of
* the target URI. The parts are joined with the host name
* of the URL of the current document.
* @param text: optional string
* Text for the menu item; the default is the target URI.
* @constructor
*/
function Item(uriParts, text)
{
/**
* URI of the target resource
*/
this.uri = uriParts.join(window.location.host);

/**
* Text for the menu item
*/
this.text = text || this.uri;
}

var imageArray = new Array(
new Item(
new Array("ecwp://", "/massey/images/massey/massey_07_fullres.ecw"),
"Massey 2007"
),
...
);

You should then get informed how HTML `select' and `option' elements work,
or RTFM of your "menu" script of which you have not even posted the relevant
parts here.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
 |  Next  |  Last
Pages: 1 2
Prev: Ugh
Next: Artificial Intelligence updated 2008 May 4