javascript - dwr addoptions with associative array -


i have associative array.i want able add options dropdown using associative array key value option , array key text of option element.

 var associativearray = new array();  associativearray['city'] = "portland";  associativearray['state'] = "oregon";  associativearray['country'] = "united states";  dwr.util.addoptions(makeid3.id,associativearray); 

doing above creates options elements text , value :

<option value="city,portland">city,portland</option> 

however expecting following:

<option value="city">portland</option> 

how can achieve above dwr , associative arrays.could suggest?

use object rather array:

var associativearray = {     city: "portland",     state: "oregon",     country: "united states" }; dwr.util.addoptions(makeid3.id, associativearray, false); 

or if want add properties dynamically, use:

var associativearray = {}; associativearray['city'] = "portland"; associativearray['state'] = "oregon"; associativearray['country'] = "united states"; 

see documentation. treats array argument differently object.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -