Skip to content Skip to sidebar Skip to footer

Disable Text Selection On Input Fields

I am developing a Hybrid application using IBM Worklight, HTML5, CSS3 and javascript. Is there any possible way to disable text selection on input fields? I have a username and pas

Solution 1:

you can use below code to disable copy and paste

$('input,textarea').bind('cut copy paste', function (e) {
    e.preventDefault(); //disable cut,copy,paste
});

Solution 2:

To disable pasting text into input field,

$('#myInput').bind('input', function(e) {
    $("#myInput").val("");    //This will reset input value to empty
});

Solution 3:

There is an answer already on SO for selecting that will probably give you what you need: Prevent element from taking part in text selection

There are also answers on SO for disabling pasting on some browsers: Disable pasting text into HTML form

Keep in mind though that the above will not work in every browser.

Post a Comment for "Disable Text Selection On Input Fields"