I have a function that, when clicking on the dropdownlist, it checks and changes the mask of a field:
function HideTextBox(ddlId) {
var ControlName = document.getElementById(ddlId.id);
if (ControlName.value == 'P') //it depends on which value Selection do u want to hide or show your textbox
{
document.getElementById('txtCpf').style.display = '';
$("#txtCpf").mask("999.999.999-99");
} else {
document.getElementById('txtCpf').style.display = '';
$("#txtCpf").mask("99.999.999/9999-99");
}
}
This is my html:
<div class="grid-1-3 margin-txt">
<asp:Label ID="Label5" runat="server" Text="Tipo de Pessoa:"></asp:Label>
<asp:DropDownList ID="ddlIDType" runat="server" onchange="HideTextBox(this);" CssClass="form-control">
<asp:ListItem Value="P">Física</asp:ListItem>
<asp:ListItem Value="L">Jurídica</asp:ListItem>
</asp:DropDownList>
</div>
<div class="grid-1-3 margin-txt">
<asp:Label ID="Label4" runat="server" Text="CPF ou CNPJ"></asp:Label>
<asp:TextBox ID="txtCpf" runat="server" CssClass="form-control" placeholder="CPF ou CNPJ" required="required"></asp:TextBox>
</div>
But when I do not select the field, it does not load the mask, how can I call the function in the form's load, passing the field "ddlIDType"? I tried to pass it like this, however it returns me error:
ScriptManager.RegisterClientScriptBlock(this, GetType(), "", "HideTextBox(" + ddlIDType.SelectedValue + ");", true);
Error that is returning me when I load the function in this way in load:
Uncaught ReferenceError: HideTextBox is not defined