0

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"

Lücks
  • 3,806
  • 2
  • 40
  • 54

2 Answers2

0

I know that there is a jquery function to addClass() and removeClass(). So you could do something like:

$(".f").click(function(){
       this.addClass("NeedMask");
    });

I'm actually at work atm but this should get you started in the right direction. I'd check the jQuery docs for help on masking (you'll also want to use $(".J").removeClass("NeedMask")

Chazt3n
  • 1,641
  • 3
  • 17
  • 42
0

Done!

@Html.RadioButton("RbTest", "F", true, new { @onclick = "Mask1()" })
@Html.RadioButton("RbTest", "J", false, new { @onclick = "Mask2()" })
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Lücks
  • 3,806
  • 2
  • 40
  • 54