0
I have the code below as an input for the date , works well on all browsers except in Firefox. It probably has something to do with the event.returnValue=false
be ignored by browser, as I fix this?
<html>
<script language="JavaScript">
function Data(evento, objeto){
var keypress=(window.event)?event.keyCode:evento.which;
campo = eval (objeto);
if (campo.value == '00/00/0000')
{
campo.value=""
}
caracteres = '0123456789';
separacao1 = '/';
conjunto1 = 2;
conjunto2 = 5;
if ((caracteres.search(String.fromCharCode(keypress))!=-1) && campo.value.length < (10))
{
if (campo.value.length == conjunto1 )
campo.value = campo.value + separacao1;
else if (campo.value.length == conjunto2)
campo.value = campo.value + separacao1;
}
else
event.returnValue = false;
}
</script>
</head>
<body>
<form method=post action="">
Data: <input type="text" name="txtdata" pattern="[0-9]" maxlength="10" size="10" onKeyPress="Data(event, this)">
</form>
</body>
What is the intention with this Event.returnValue = false?
– Diego Marques
The intention is that the input box does nothing if the if is not true, but firefox simply inserts the typed key as text input.
– Juscelino DORNELES