[thelist] JS array or something else?

Jerry Scannell JerryScannell at cox.net
Thu Nov 7 10:38:01 CST 2002


FYI  javaScript does have an associative array mechanism.  I use it for form
field names.  here's an example

<script language="javascript">
function testName()
{
   var strName = document.yaddy[ "first_name" ].value;
   alert ( "I got " + strName );
   return true;
}
</script>

<form name = "yaddy">
<input type="text" name="first_name"> value = "who cares"
onBlur="testName()">
</form>


Jerry
----- Original Message -----
From: "Burhan Khalid" <burhankhalid at members.evolt.org>
To: "Tom Dell'Aringa" <thelist at lists.evolt.org>
Sent: Thursday, November 07, 2002 11:21 AM
Subject: Re: [thelist] JS array or something else?


> 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';     file://$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 |
> *-----------------------------------------------*
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>




More information about the thelist mailing list