Hi guys.
Do you know how to put an event attribute on a Forms input field?
I´m doing like this, but it does not work.
Hi guys.
Do you know how to put an event attribute on a Forms input field?
I´m doing like this, but it does not work.
The way I would do it would be...
Give a class name to the field, say CSS Class: MyField
Then in Javascript
$(document).ready( function() {
$('.MyField input').on("onkeyup", function() {
$(this).val( number($(this).val()));
});
});
This is hand typed here and untested so beware of minor syntax errors.
Im doing this but it does not work, yet
$(document).ready( function() {
$(".limite input").on('onkeyup', function() {
Numeros($(this).val());
});
function Numeros(string){//Solo numeros
var out = '';
var filtro = '1234567890';//Caracteres validos
//Recorrer el texto y verificar si el caracter se encuentra en la lista de validos
for (var i=0; i<string.length; i++)
if (filtro.indexOf(string.charAt(i)) != -1)
//Se añaden a la salida los caracteres validos
out += string.charAt(i);
//Retornar valor filtrado
return out;
}
});
I can see a few possible issues with the code so far.
Most important is it should be .on('keyup',... not .on('onkeyup',...
Second, you're returning the "out" variable, but you're not actually using it to update your input field value or anything.
It looks like you are trying to limit the input field to numbers only. If so, why don't you just use a Number type field and let Forms handle that for you?
Thanks!!!
That field is only for adding a custom CSS class to the input element; there is no out-of-the-box way to add event attributes.
If you want to add a custom event handler, you need to do it with code in the JavaScript tab like what James describes in his post.