0

I want to disallow user from select a content of input control by css. Im trying to add the following attributes to the control:

 #editContainer
  {    
     user-select: none
    -webkit-user-select: none
    -khtml-user-select: none
    -moz-user-select: none
  }

<div id='editContainer'>
    <input id='daysInput' />
     <span id='daysString'></span>
     <input id='hoursInput' />
     <span>:</span>
     <input id='minuteInput' />
</div>

but it is not working...

how can i prevent from users to select content of controls?

Ortal Blumenfeld Lagziel
  • 2,415
  • 3
  • 23
  • 33

3 Answers3

1

You need to add the following:

-moz-user-select: none; 
-webkit-user-select: none; 
-ms-user-select:none;
 user-select:none;' 
 unselectable='on'  
onselectstart='return false;'  
onmousedown='return false;'

For example:

<input  style='-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;'  unselectable='on'  onselectstart='return false;'  onmousedown='return false;' id='daysInput' />
Ortal Blumenfeld Lagziel
  • 2,415
  • 3
  • 23
  • 33
0

You can't do this with text input fields, if they are focused (i.e. opened for editing)

It will work only with attr. disabled="disabled"

<div id='editContainer'>
    <input id='daysInput' disabled="disabled" value="Test"/>
     <span id='daysString'></span>
     <input id='hoursInput'  disabled="disabled" value="Test"/>
     <span>:</span>
     <input id='minuteInput'  disabled="disabled" value="Test"/>
</div>

Check out this example http://jsfiddle.net/ce7st2ms/7/

you-rick
  • 185
  • 1
  • 3
  • 12
0

I do not think you'll find a good solution for this.

The only (JavaScript) way I see, is to use several elements and position absolute. The top element (div or any other you like) should have the same size if input. This element can prevent selection.

In the case you need input some data to input field, you temporary hide this element and back when input finished.

Max
  • 1,090
  • 10
  • 23