2
Well here’s the thing, I have a file. JS in my project.
I’m calling him at HEAD LIKE THAT:
<script type ="text/javascript" src="~/JS/validacao.js"></script>
within this validation.JS has a mask function.
and put in Textbox the following event.
this.TxtCEP.Attributes.Add("onkeypress", "Mascara(CEP, TxtCEP);");
<asp:TextBox ID="TxtCEP" runat="server" style="margin-left: 66px" Width="231px" TextMode="Number" MaxLength ="8"></asp:TextBox>
Mascara function
function Mascara(formato, objeto) {
campo = eval (objeto);
// CEP
if (formato=='CEP'){
var CodCar = event.keyCode;
if (CodCar < 48 || CodCar > 57) {
campo.focus();
event.returnValue = false;
}
separador = '-';
conjunto1 = 5;
if (campo.value.length == conjunto1) {
campo.value = campo.value + separador;
}
}
}
But it’s not working.
I’m doing right ?
also put the function Mascara
– HudsonPH
Press F12 and look at the console and post the errors tbm
– HudsonPH
you have to use so src="~/JS/validation.js" where the
~
would be the root folder of your project.– Pablo Tondolo de Vargas
How is your folder structure? Is the JS folder in the project root, or is it inside another folder? Most likely you have a script folder and the JS is inside it, then your reference has to be like this
src="~/script/JS/validacao.js"
, recalling that the~
is defined as root Operator by Asp.net– Pablo Tondolo de Vargas
the wrong path ta follows @Pablotondolodevargas' solution
– HudsonPH
I already changed it, still nothing.
– Antonio_Sistema_de_Informacao
Updates the question with the modifications you have made and with the error message you are giving now
– Pablo Tondolo de Vargas
first I didn’t realize it was webforms, second mind I’m adding the answer
– Pablo Tondolo de Vargas