Search code examples
c#javascriptasp.net-mvc-3radio-buttonmaskedinput

RadioButton with Javascript (MVC3)


I'm working with C# and MVC3

I have a RadioButton, and depending on the option selected I need to change the mask of a textbox. I'm using Masked Input Plugin for jQuery.

How can I do this? I have to develop it on the Controller or on the .cshtml?

    <div class="editor-field">
        @Html.LabelFor(model => model.Type)
        @Html.Label("Test Label")
        @Html.RadioButtonFor(model => model.RbTest, "F", true)

        @Html.Label("Test Label 2")
        @Html.RadioButtonFor(model => model.RbTest, "J")

        @Html.LabelFor(model => model.LabelBla)
        @Html.EditorFor(model => model.NeedMask)
    </div>

If I choose "F" (First RadioButton) I want to have a mask. If I choose "J" (Second RadioButton) I want another mask.

I need to mask the Editor: "NeedMask"


Solution

  • Done!

    @Html.RadioButton("RbTest", "F", true, new { @onclick = "Mask1()" })
    @Html.RadioButton("RbTest", "J", false, new { @onclick = "Mask2()" })