Click to See Complete Forum and Search --> : Interesting Question....


petermar30030
06-26-2003, 08:15 PM
Is It Possible To Create A New Array That Will Hold A value such as an Amount Of Money or A Username And Password?
If So can Some-one Please Give Me A well Commented Script?
I'd Really Apreciate it.:cool:
P.S
Incase Your Wondering, The Only Reason I pick That Smiley Face is Because I think it looks cool

Jona
06-26-2003, 08:22 PM
It's very simple. I'm not sure what you would use it for, because it's simply insecure and should not be done with client-side code. Regardless, here is an array example:


<script type="text/javascript">
<!--
var myArray = new Array("a", "b", "c");
for(i=0;i<myArray.length;i++){alert(myArray[i]);}
//-->
</script>


[Jona]

Charles
06-26-2003, 08:24 PM
You're going to have to give us a whole lot more information than that. Describe your project in English and in great detail.

And if you are going to be pairing user names with passwords then you will be wanting to use an Object.

<script type="text/javascript">
<!--
keys = {North:'fee', South:'fie', East:'foe', West:'fum'}
keys.Up = 'foo'
alert (keys.North);
alert (keys['Up']);
// -->
</script>

And never lose sight of the fact that JavaScript will not work 13% of the time. It is very important, therefore, to be certain that yor page will still work for those good people.

Charles
06-26-2003, 08:28 PM
And Jona's example can be shortened a wee bit thus:

<script type="text/javascript">
<!--
a = ['a', 'b', 'c'];
for (i in a) {alert(a[i])}
// -->
</script>

Jona
06-26-2003, 08:36 PM
Originally posted by Charles
And Jona's example can be shortened a wee bit thus:

And you can always trust Charles to come back and improve anything I do. :)
Forgot all about the var in var thing. :p
Must.... Get... Book!!

Jona