Here is a completed function that will populate a select box with data in an
XML format (XML format below):

// fill the <select> dropdown list box
// @ajax response (transport as returned above)
// @id of the select field (defaults to elFieldName
// @xml_data_node_name (our dataset uses 'state')
function fillSelectList(transport, select_id, xml_data_node)
{
  var states,
      state,
      selbox,
      options;
  // Get & validate response
  states = transport.responseXML.getElementsByTagName(xml_data_node);

  $(select_id).options.length = 1;
  for(var i = 0; i < states.length; i++)
  {
    var value = states[i].getAttribute('value');
    var name= states[i].getAttribute('name');
    // i+1 allows us to skip over the first item in the
    // pulldown which prompts the user to "Pick One"
    $(select_id).options[i+1] = new Option(name, value, null, false);
  }
}

XML Data
<data>
  <first>John</first>
  <last>Doe</last>
  <email>[email protected]</email>
  <states>
      <state value="AL" name="Alabama" />
      <state value="GA" name="Georgia" />
      <state value="FL" name="Florida" />
      <state value="CA" name="California" />
  </states>
</data>

 Thanks to T.J. and Colin Mollenhour for their help on this!

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to