Click to See Complete Forum and Search --> : Binding multiple variables to a array?


Shampie
09-29-2003, 03:40 PM
Hello,

I am wondering how to this:
var sufsel = new Array(3)
sufname[0] = "option1"
sufname[1] = "option2"
sufname[2] = "option3"

when option 1 is called it would need to fill in a couple of other information, say option1 will give up:

textboxa.value = option1
textboxb.value = black
textboxc.value = circel etc..

var sufsel = new Array(3)
sufname[0] = "option1",1,1
sufname[1] = "option2",1,2
sufname[2] = "option3",2,1

option1 will give option1 black circel
>>
form
1 circel
2 square

color
1 black
2 white
3 green
///
my direction would go to:
var sufsel = new Array(3,form,color)
sufname[0] = "option1",1,1
sufname[1] = "option2",1,2
sufname[2] = "option3",2,1

can anyone help me, example script or fill up mine?

thank you for your time!

Charles
09-29-2003, 03:47 PM
<script type="text/javascript">
<!--
alert ([{name:'option 1', form:'circle', color:'black'}, {name:'option 2', form:'circle', color:'white'}, {name:'option 3', form:'square', color:'black'}][1].color)
// -->
</script>

Shampie
09-29-2003, 08:26 PM
thanks you, but this is not exactly what i was looking for.

say a,b,c,d,e,f are properties (which fill in textboxes or dropdownlists)

with 1 option from the array selected all properties will be filled in aswell.

var sufsel = new Array(a,b,c,d,e,f)
sufname[0] = "1", "2, "3", "4", "5", "6"
sufname[1] = "option2"
sufname[2] = "option3"

say a = blaat.value;
so when sufname[0] is selected a = 1, which means blaat.value = 1.

does this explain better.

Charles
09-30-2003, 04:51 AM
Originally posted by Shampie
does this explain better. No, I'm afraid it doesn't.

Shampie
09-30-2003, 10:30 AM
<script>
var a = 0;
var b = 0;
var wpnname = new Array(8)
wpnname[0] = "sword" ,a=3,b=1
wpnname[1] = "katana", a=7,b=2
wpnname[2] = "scimitar", a=5,b=4
wpnname[3] = "blade", a=6,b=6
wpnname[4] = "spear", a=5,b=9
wpnname[5] = "hammer", a=7,b=6
wpnname[6] = "axe", a=5,b=6
wpnname[7] = "scepter", a=5,b=6
wpnnameR = prompt("array#?",0);

i=wpnnameR;
alert(""+wpnname[i]+" "+a+" "+b+"");
//}
</script>


I want the alert message to display the numbers given in array. When I give '4' at wpnnameR the alert should display "spear, 5 ,9", this is what I am looking for.

I hope this will clear up bit more.
Thanks!

Shampie
09-30-2003, 12:08 PM
<script>
var a = 0;
var b = 0;
var wpnname = new Array(8)
wpnname[0] = "sword,3,1"
wpnname[1] = "katana,7,2"
wpnname[2] = "scimitar,5,4"
wpnname[3] = "blade,6,6"
wpnname[4] = "spear,5,9"
wpnname[5] = "hammer,7,6"
wpnname[6] = "axe,5,6"
wpnname[7] = "scepter,5,6"
wpnnameR = prompt("array#?",0);

i=wpnnameR;

getinfo = wpnname[i];
getinfo = getinfo.replace("/,\s/g", ",");
inf = getinfo.split(",");
inf.sort();
alert ("item:"+inf[i,2]+""+inf[i,1]+""+inf[i,0]+"");

//}
</script>

This seems to work, i've been trying for quitte a while and this is what came up..

Charles
09-30-2003, 12:39 PM
What I posted above is exactly what you are looking for. Read up on Object literals and associative arrays while I work on a better example.

Charles
09-30-2003, 12:54 PM
<script type="text/javascript">
<!--
var wpnName = new Array(8)
wpnName[0] = {name:'sword', field1:3, field2:1}
wpnName[1] = {name:'katana', field1:7, field2:2}
wpnName[2] = {name:'scimitar', field1:5, field2:4}
wpnName[3] = {name:'blade', field1:6, field2:6}
wpnName[4] = {name:'spear', field1:5, field2:9}
wpnName[5] = {name:'hammer', field1:7, field2:6}
wpnName[6] = {name:'axe', field1:5, field2:6}
wpnName[7] = {name:'scepter', field1:5, field2:6}

weapon = wpnName [prompt("array#?",0)]

alert (['item:' + weapon.name, weapon.field1, weapon.field2])
// -->
</script>

Though, the following may be more useful.

<script type="text/javascript">
<!--
weapons = new Object();
weapons.sword = [3,1]
weapons.katana = [7,2]
weapons.scimitar = [5,4]
weapons.blade = [6,6]
weapons.spear = [5,9]
weapons.hammer = [7,6]
weapons.axe = [5,6]
weapons.scepter = [5,6]

alert (weapons.axe)
// -->
</script>

Shampie
09-30-2003, 02:01 PM
your help is very much appreaciated, tough right now I am working out the way I made it I will certainly have a good look on your way.

mm perhaps it is time to obtain a javascript book, I don't know my way with objects.

Thank you once more!

Charles
09-30-2003, 03:54 PM
Originally posted by Shampie
I don't know my way with objects.Please note, JavaScript is an object oriented language.

Shampie
09-30-2003, 07:02 PM
let me rephrase that, I aint no pro with javascript, I learn every day from anwsers by helpfull and skilled people like you.
I comparing with you I hardly know my way with objects and their posibilities.
Therefor I am thankfull for your time!