tags:

views:

44

answers:

1

Here is the problem. lets say I have a product category table and a product table. by using foreach statement getting categories making them a html table and putting products inside the table as a radio group. so 3 product categories makes three different html table and inside the tablo i m listing the product as radio buttons.

when user selects an product i'm using jquery post statement and send some data. I'm using below jqeuery to understand which radio button selected.

$(document).ready(function () {
    $("input[name='AD']:radio").change(function () {
        var data = $("input[name='AD']:checked").val();
        $.post("/Configure/UpdateAd/", { id: $(this).val() }, function (data) {
            update($("#bottomRightA"), data);
        });
    });
});

And it works! but

here I have a problem. input[name='up']

I m using this way to differentiate radio groups based on category.

input type="radio" name="<%: model.CategoryName%> value="<%:model.CategoryId%>"

if I make all radio buttons name 'up', they become the same group as expected. and I cant tell the jquery which radio group is selected. Is there a way to use jquery with some kind of mvc nuggets?. Like below

input[name='" + <%: model.CategoryName + "']

or anything I can do with jQuery?

Thnx.

+2  A: 

If I understand you right, you want to hook up all radio buttons, but treat the categories separately.

You can pick up the name of the changed radio button and use that in the code:

$(function () {
  $("input:radio").change(function () {
    var name = $(this).attr("name");
    var data = $("input[name='"+name+"']:checked").val();
    $.post("/Configure/Update"+name+"/", { id: data }, function (data) {
      update($("#bottomRightA"), data);
    });
  });
});
Guffa
not nuggets, but jQuery. You are the savior man! Thanx a lotI need to work on jquery a little bit more. Also thanx for helping me realizing this.!