[thelist] JS array or something else?

Burhan Khalid burhankhalid at members.evolt.org
Thu Nov 7 10:31:01 CST 2002


Hey Tom :

TDA> The way I figured I should do this is possible build an array, but
TDA> what I really need is a key/value pair I think.

You are right on that part. However, I don't know if javascript has a
two key-value (also called associative) array option. However, seeing
as how you are only worried about one key, a regular array (which has
a subscript) should work :

(this code is php) :
  $selection[]='0';
  $selection[]='a';     //$selection[1]
  ...
  $selection[]='z';

  now, to get the selection from a key (which I am assuming you will
  get from the form, you can just pull up the appropriate value) :

  echo $selection[$key];

Again, I apologize, but I don't know the javascript particulars, but
in theory, that should work. You will need the index ("key") to get
to the item in the array ("value"). For this to work, you need to
already have an array populated with your key value pairs.

Another thought that I just had (again, I don't know if this is
possible in javascipt) -- was to use the ASCII key codes (which
increase by one). You can get the key code for small letter 'a' (lets
pretend its 56) -- and then on each button press, increase that
number. I know that each number increase puts out the next letter (so,
in our example 57 would be 'b').

Hoping this helps,

--
*---------------*
| Burhan Khalid |
*---------------*-------------------------------*
| Email : burhankhalid[at]members.evolt.org     |
| Web   : members.evolt.org/burhankhalid        |
| ICQ   : 6016166                               |
| AIM   : digitz0819                            |
| MSN   : burhankh[at]hotmail.com               |
| Yahoo : burhan_khalid                         |
*-----------------------------------------------*
| mushkil hai zabas kalaam mera ai dil          |
| sun sun ke ise suKhan_varaa.N-e-kaamil        |
| aasaan kahane kii karate hai.n faramaaish     |
| goim mushkil vagaranaa goim mushkil           |
|-----------------------------------------------|
| Too hard to grasp is my verse, O heart!       |
| Hearing it, the connoisseurs of art           |
| For a simpler style do ask                    |
| Difficult, if I write, difficult, if I do not |
*-----------------------------------------------*




More information about the thelist mailing list