I'm having a problem with the following code:

I have the following jquery call: the problem is that I have several <select name="^DDLColumns1..2..3..4. etc.. controls on my page, however this is only populating the first one: <select name="^DDLColumns1"

anybody know why the select would do this?

<script type="text/javascript" language="javascript">  
        $().ready(function() {
            $.ajax({
                type: "POST",
                url: "Default.aspx/GetColumns",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $('select[name^=DDLColumns]').get(0).options.length = 0;
                    $('select[name^=DDLColumns]').get(0).options[0] = new Option("Select Column", "-1");

                    $.each(msg.d, function(index, item) {
                        $('select[name^=DDLColumns]').get(0).options[$('select[name^=DDLColumns]').get(0).options.length] = new Option(item, item);
                    });
                },
                error: function() {
                    alert("Failed to load columns");
                }
            });
        });


    </script>

here is a sample of the second group of many....

 <!-- Second Search Condition -->

   <div class="container">
    <fieldset><legend>Search Condition 2</legend>
       <div class="fltlft"> 
            <label>Columns:</label>
           [B] <select name="DDLColumns2" id="DDLColumns2" size="1"></select>[/B]
            <br />
            <label>Group By</label>
            <input name="GroupBy2" type="checkbox" value="" />
        </div>
       <div class="fltlft">
            <label>Condition:</label>
            <select name="DDLConditional2" size="1">
                <option selected="selected">is equal to</option>
                <option>begins with</option>
                <option>is between</option>
                <option>is not equal to</option>
                <option>is greater than</option>
                <option>is less than</option>
            </select>

      </div>
        <div class="fltlft">
            <label>Value:</label> <input name="WhereText2" type="text" size="15" />
            <br /><label id="AndLbl2" style="display:none">and</label>
            <input name="BetweenText2" id="BetweenText2" style="display:none" type="text" size="25" />

        </div>
  </fieldset>
  </div>
      <div class="clearfloat"></div>

what am I doing wrong with the select[name^=DDLColumns] piece? I've seen examples of finding all checkboxes this way...

Thanks anybody...

LGR,

I think you need to loop inside the success callback fn.

With a loop counter i counting up from 0 try replacing get(0) with get(i) (4 times).

I'm not sure about $.each . Maybe is disappears if loop is employed.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.