Ideas, vivencias y demás
Peru Blogs

August 26, 2009

Deshabilitar el backspace y el enter cuando no estan siendo usados en controles

Encontré lo que necesitaba!, código para bloquear el backspace y el enter si no se esta dentro de un control en el webform. Aquí la fuente y aquí el código:

// Trap Backspace(8) and Enter(13) -
// Except bksp on text/textareas, enter on textarea/submit

if (typeof window.event != ‘undefined’) // IE
  document.onkeydown = function() // IE
    {
    var t=event.srcElement.type;
    var kc=event.keyCode;
    return ((kc != 8 && kc != 13) || ( t == ‘text’ &&  kc != 13 ) ||
             (t == ‘textarea’) || ( t == ’submit’ &&  kc == 13))
    }
else
  document.onkeypress = function(e)  // FireFox/Others
    {
    var t=e.target.type;
    var kc=e.keyCode;
    if ((kc != 8 && kc != 13) || ( t == ‘text’ &&  kc != 13 ) ||
        (t == ‘textarea’) || ( t == ’submit’ &&  kc == 13))
        return true
    else {
        //alert(’Sorry Backspace/Enter is not allowed here’); // Demo code
        return false
    }
   }

1 Comment »

The URI to TrackBack this entry is: http://luismarcel.blogsome.com/2009/08/26/deshabilitar-el-backspace-y-el-enter-cuando-no-estan-siendo-usados-en-controles/trackback/

  1. me sirvió =)

    Comment by jose koji — November 30, 2009 @ 9:56 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.


Escribe lo de la imagen






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham