Re: to fill a select with json javascript from arrays [message #175073 is a reply to message #175072] |
Wed, 10 August 2011 12:51 |
Erwin Moller
Messages: 228 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 8/10/2011 2:13 PM, nawfer wrote:
> in JSON/javascript if I have 3 php’s array, how can insert their values in
> 3 selects?
> the select also must to be dependant; example Car Brand->Car
> Model->Accessories
> I look guide but cannot understand how solve the problem
>
>
> ARRAY BRAND
> brand[01]='Brand 1';
> ...
> brand[20]='Brand 20';
>
> ARRAY MODEL (every brand have 3 models,total 60 models)
> model[01][m01]=’model m01 of brand 1’;
> model[01][m02]=’model m02 of brand 1’;
> ...
> model[20][m59]=‘model m59 of brand 20’;
> model[20][m60]=‘model m60 of brand 20’;
>
> ARRAY ACCESSORIES (every models can to have n accessories; exmpl. m01-> 3
> accessories,
> m60 -> 2 access.)
> accessories[m01][]=‘accessories 1 of model m01’;
> accessories[m01][]=‘accessories 2 of model m01’;
> accessories[m01][]=‘accessories 3 of model m01’;
> ……..
> accessories[m60][]=‘accessories 1 of model m60’;
> accessories[m60][]=‘accessories 2 of model m60’;
>
Hi,
This is actually a JavaScript/JSON question.
What you probably need is something like this:
[Javascript]
for (var key in someArray){
var theValue = someArray[key];
// do stuff
}
which is a little like PHP's:
foreach ($someArray as $key => $theValue){
}
Whit that approach you'll have the key of some array, which you will
need in your accessories-array to look up the different values.
Regards,
Erwin Moller
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
|
|
|