Affan Shahab
Affan Shahab

Reputation: 888

How to unmask/disable or clear a textbox in JavascriptJquery using MVC razor

I have a text box

<input type="text" id="mytextbox" name="searchField"/>

and three radio buttons. I need to mask text box on select of specific radio button selection. I have successfully done with it. But on third radio button I want text box to just clear without any masking, just an open field. So, if we select Radio button 1, Text Box will masked accordingly but then we select Radio button 3. Masking remain in place. I want to remove it then.

Forgive the bad English. Thanks is advance.

Code used for masking.

$("#mytextbox").mask("999-9999-9999");

Upvotes: 0

Views: 1501

Answers (1)

Sachu
Sachu

Reputation: 7766

You can refer the sample code below..

$(document).on('click', "input:radio[name=xxxx]", function () {

          var val = $("input:radio[name=xxxx]:checked").val();       
              var mask = "999-9999-9999";
            if(val == "the value of 3rd radiobutton")
               {

                 $("#mytextbox").unmask(mask);
                 } 
             });

Upvotes: 1

Related Questions