$('form').loadJSON(data) and SELECT

$('form').loadJSON(data) and SELECT

I would appreciate some insight here:

I am used to drop downs being bound to database fields

I have a select drop down on a form used to populate the insert/update query sent to the server.

 
<td><select required id="position" name="position" onChange="changeFlag(1)" > <option value="0">Select <option value="1">Board Member <option value="2">Administration <option value="3">General Member </select></td>

When I repopulate the form field with JSON

$('form').loadJSON(data);

, I expect the data from the database field to be displayed. All the other form input fields are populated correctly.

By the way, this: onChange="changeFlag(1) is not calling anything. A dummy

In reading:

Populating form element Form is populated with JSON object using the following JavaScript call: $('form').loadJSON(data); This call matches object properties with the form elements by name and depending on the type of the form element populates value. Following rules are used while the form elements are populated:

Multiple selection lists

When plugin matches property with multiple selection list element, it expect that property is array of values that should be selected in the list. Plugin selects all values in the multi selection list that exist in the property of the JavaScript object.

Assuming that a "select" control comes under the definition of "Multiple selection lists", it sounds as if it would work and display the applicable JSON content.

I set up a test with a select where I use a button to change the "value" of the select index and that works fine.

Evidently, $('form').loadJSON(data), does not address the indexing as implied above.


http://www.perlmonks.org/?node_id=1211530