Results 1 to 2 of 2

Thread: [RESOLVED] determining RadioButtonFor

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Resolved [RESOLVED] determining RadioButtonFor

    Hi All,

    in my markup I Have:
    Code:
    <tr>
                            <td>@Html.LabelFor(model => model.CustomerLoanOfVehicleExtension, null, null, null)</td>
                            <td>@Html.CheckBoxFor(model => model.CustomerLoanOfVehicleExtension)</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.CustomerLoanOfVehicleValue, "CCL", new { @class = "optVehicleExt" })@Html.LabelFor(model => model.ContingentCoverLoadValue, null, null, null)</td>
                            <td>&nbsp;</td>
                            <td>@Html.EditorFor(model => model.ContingentCoverLoadValue)</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>   
                        </tr>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.CustomerLoanOfVehicleValue, "FCL", new { @class = "optVehicleExt" })@Html.LabelFor(model => model.FullCoverLoadValue, null, null, null)</td>
                            <td>&nbsp;</td>
                            <td>@Html.EditorFor(model => model.FullCoverLoadValue)</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>   
                        </tr>
    and then in JQuery I have:

    Code:
    function customerLoanOfVehicle() {
                if ($("#CustomerLoanOfVehicleExtension").is(":checked")) {
                    $(".optVehicleExt").removeAttr("disabled");
                } else {
                    $("#CustomerLoanOfVehicleValue").attr("disabled", "disabled");
                    $(".optVehicleExt").attr("disabled", "disabled");
                }
         }
    This sets my optionbuttons enabled/disabled fine based on the checkbox.

    My problem is that I cannot seem to get which of the option buttons have been set.

    If I do something like:

    Code:
    $("#CustomerLoanOfVehicleValue").click(function () {
                var value = $(this).val();
                alert(value); 
            });
    Only my first value ever gets hit. I.e. I click the option whos value is CCL and the alert says CCL, but when I click the option with FCL I get nothing?????

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: determining RadioButtonFor

    Doh...Solved it. Here's the answer for anybody else.

    On the RadioButtonFor, introduce a new id :

    Code:
    @Html.RadioButtonFor(model => model.CustomerLoanOfVehicleValue, "FCL", new { @class = "optVehicleExt", @id = "FCL"})
    Make the @id unique for each radiobutton then in JQuery as normal you can do:

    Code:
    $("#FCL").click(function () {
                ............
            });
    Works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width