473,378 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

naming array values?

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
Jun 27 '08 #1
5 1532

"Pukeko" <pu************@gmail.comwrote in message
news:ea**********************************@i36g2000 prf.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
Jun 27 '08 #2
On May 5, 2:24*am, "Tim Williams" <timjwilliams at gmail dot com>
wrote:
"Pukeko" <pukeko.tani...@gmail.comwrote in message

news:ea**********************************@i36g2000 prf.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...
Jun 27 '08 #3
Tom Cole <tc****@gmail.comwrote:
>
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
Jun 27 '08 #4
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</codeobject.
*
* @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
Jun 27 '08 #5
Tom Cole wrote:
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.
Because you are not storing array elements then, but augment the Array object.
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";
And why not? Array objects are native objects and, some properties with the
ReadOnly attribute aside, native objects can be augmented with any number of
properties.
However if you call alert(images.length) you will get 0.
It helps to use a collection implementation instead.
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.
var a = ["x", 42];
a["foo"] = "bar";

var out = [];

for (var key in a)
{
var p = a[key];
var t = typeof p;
if (t == "string")
{
p = '"' + p.replace(/"/g, "\\$&") + '"';
}

out.push(key + ": " + t + " = " + p);
}

// displays the enumerable properties of `a'
// and the objects in its prototype chain
window.alert(out.join("\n"));

Note that this can be useful with a collection implementation; if a
collection is not required, then one should use an Object object
instead of an Array object.
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.
Provided one does not augment Object.prototype or Array.prototype, it is not
as hard to implement as you think.
You will probably need two arrays, one to store the "names" and the
other to store the "values".
No, this is not necessary. You can create user-defined objects that are
elements of the array instead.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties...
3
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
5
by: Allan Ebdrup | last post by:
Does anyone have some good pointers to good naming conventions preferrably by MS. Another developer and I had a discussion on the naming of a public property that contains a collection of...
6
by: Ed Jay | last post by:
<disclaimer>New to js.</disclaimer> I have several pages, each with menues comprising checkboxes or radio boxes within the same form. I presently 'brute force' clear the buttons with individual...
14
by: Cylix | last post by:
I have a array to store some student information, eg var s = new Array('2006001', 'Apple Joker', '5B'); normally, We get the data using s, s,s ... How can I define them more readable like s, s,...
3
by: Phillip Conrad | last post by:
Here is a little problem I've run into, and none of the naming conventions have helped... Ever since I switched from C to C# and FxCop, I've going crazy trying to fix some style issues. I have 3...
3
by: Nathan Sokalski | last post by:
I have written a custom control that uses AJAX (it implements IPostBackDataHandler and ICallbackEventHandler). I have tested it, and it seems to work the way I want. However, when I used it in...
2
by: Bill Pursell | last post by:
In libabc, I have a function which takes a NULL-terminated array of character strings. A second, closely related function take a NULL-terminated array of void *: abc_foo( char ** ); abc_vfoo(...
23
by: Thorsten Kampe | last post by:
Okay, I hear you saying 'not another naming conventions thread'. I've read through Google and the 'naming conventions' threads were rather *spelling conventions* threads. I'm not interested...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.