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?

2

3 Answers 3

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' />
Sign up to request clarification or add additional context in comments.

Comments

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/

1 Comment

I dont want that the control will be disabled I want to allow user to change the content on it... I dont want that the user select the control's text
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.