jQuery UI dropdown/selectable

jQuery UI dropdown/selectable

Very new to jQuery & jQuery-ui, and have a problem I can't seem to get working like I want it to work.

I'm using a $.get to do an ajax call to a sql stored procedure & return data in an XML format.  In the callback part of the get, I create a function that builds a dropdown from the items returned.  I also build an additional <option> line & prepend it to the select.  I've tried both the select that's part of jQuery & the .selectable that's part of jQuery-ui.

The code I'm using to build the box follows:
  1. $.get(sURL, function(data) {
  2. var select = $("#dList");
  3. //var blankline = $("<option value='' selected='selected'></option>");
  4. //select.prepend(blankline);
  5. var selectline = $("<option value='0' selected='selected'>Select Destination</option>");
  6. select.prepend(selectline);
  7. $(data).find("Row").each(function() {
  8. var mgid = $(this).find("MessageGroupID").text();
  9. var gname = $(this).find("GroupName").text();
  10. var option = $("<option>" + gname + "</option>");
  11. option.attr("value", mgid);
  12. select.append(option);
  13. });
  14. $("#dList").selectable();
  15. });

The code I use to remove the instruction that's currently shown (or the blank line) is as follows:

  1. $("#dList").one('mousedown', function() {
  2. $("option:first",this).remove();
  3. });

The XML that is the input to the dropdown is:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Rowsets DateCreated="2013-05-08T08:42:18" EndDate="2013-05-08T08:42:18" StartDate="2013-05-08T07:42:18" Version="1.1.1">
  3. <Rowset>
  4. <Columns>
  5. <Column Description="MessageGroupID" MaxRange="1" MinRange="0" Name="MessageGroupID" SQLDataType="4" SourceColumn="MessageGroupID"/>
  6. <Column Description="GroupName" MaxRange="1" MinRange="0" Name="GroupName" SQLDataType="12" SourceColumn="GroupName"/>
  7. </Columns>
  8. <Row>
  9. <MessageGroupID>1</MessageGroupID>
  10. <GroupName>First Shift</GroupName>
  11. </Row>
  12. <Row>
  13. <MessageGroupID>4</MessageGroupID>
  14. <GroupName>Alternate First Shift</GroupName>
  15. </Row>
  16. <Row>
  17. <MessageGroupID>7</MessageGroupID>
  18. <GroupName>Temporary First Shift</GroupName>
  19. </Row>
  20. </Rowset>
  21. </Rowsets>

What is happening though is:
  • The instruction (or blank line) gets removed from the other items in the dropdown when the box is clicked on.  
  • However, what happens is that now the first row of data in the dropdown is now showing in the dropdown box, even though I haven't "selected" it, only clicked on the down arrow next to the dropdown.
  • If I do click on the first row, it doesn't trigger a change.  
  • Clicking on other rows does trigger a change, and clicking BACK on to the first row then will trigger a change (but only after clicking on a different row first).

Here is what I'd like to happen:
  1. What I want the dropdown box to do is to either be blank, or have some type of meaningful instruction in it (this is what I was using the additional option & prepending it to the select).  
  2. Secondly, I don't want that instruction to show, or if I can't suppress it, I don't want it to be selectable. Ideally, I would like for the instruction/blank to remain in the box until one of the items has been clicked on & actually selected.
  3. Thirdly, when an item in the list is selected, I want to then do an ajax call to another stored procedure to return data to populate a second dropdown list & show it.  
  4. The general behavior of the list would be for dropdown1 to be visible & populate when the page is opened.  Once dropdown1 has been selected, then dropdown2 would be visible & populate.  When dropdown2 (which would have similar behavior as described in #2 above) was selected, a 3rd page item becomes visible & enabled.  
I thought my issues might be related to limitations of the dropdown in jQuery, which is why I was trying to use jQuery-ui's version.  Any help, suggestions or instruction would be appreciated.  

Thanks!