2

Hi I am new to Jquery and Ajax stuff. please Help me in acheving my solution.

Currenlty I am populating check boxes based on my model values and doing an ajax call to get list of countries for each selected value.

Now I am trying instead of displaying Model values if user clicks on All check box I need to pass All as my selected value so that I can fetch all countries.

So below I added a new check box id saying checkBoxAll so how can I do ajax call if all is selected. Can I write if stmt?

   <div id="checkboxes">
   <% foreach (var manufacturer in Model.Manufacturer)
   {%>
<input type="checkbox" id="<%: manufacturer.Id %>" class="checkbox" value="<%: manufacturer.Description %>" /><%: manufacturer.Description %><br />
<%} %>

<input type="checkbox" id="checkBoxAll" class="checkBoxAll" value="All" /> All <br />
<input type="button" value="GetCountries" class="brands" />

 <script type="text/javascript">
$(".brands").click(function (event) {
    event.preventDefault();
    var selected = "";
    var manu = "";
    var input = "";
    $("#checkboxes input:checked").each(function () {
        manu = $(this).val();
        selected = selected + "," + manu;
        $("#SelectedBrands").val(selected);
        });
    var productInput = "";
    var myUrl = "/Countries/GetCountiresForManufacturer/" + selected;
    $.ajax({
        url: myUrl,
        type: 'get',
        success: function (data) {
            productInput = data;
         $(".divNewCountriesList").html(productInput);
        }
    });
});

1 Answer 1

1

Clean a little bit your code. When you get data back why you asign it to a new var you can use

$(div).html(data);


$('#checkboxes').each(function(){
     if(this.checked && $(this).hasClass("all")){ //or id
        //do something
     }else{
        //do something else
     }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.