0

I have a HTML5 number input type

<input type="number">

My requirement is that the user should be able to set the value only through UP & DOWN arrow (spinners). User shouldn't be able to enter the value manually. Is it possible using CSS only?

I am using node-webkit.

Similar to this approach:

3
  • What does adding readonly attribute to the input do? Commented Mar 16, 2014 at 16:49
  • 1
    i need the spinners to stay. adding readonly to input removes the spinners too! Commented Mar 16, 2014 at 16:49
  • 2
    Not possible with CSS only. Possible with javascript. Commented Mar 16, 2014 at 16:55

2 Answers 2

2

I think is not possible to use CSS only. Here is a small script to do that in case you want:

<input type="number" onkeydown="if (event.keyCode != 38 && event.keyCode != 40) {event.preventDefault()}"/>
Sign up to request clarification or add additional context in comments.

6 Comments

I'd exclude the Enter or Backspace keys as well.
@trungDQ will it on android too?
@ShouryaSharma you should consider to exclude Enter (keyCode = 13) and Backspace (keyCode = 8) keys as @Hashem suggested, just will give user ability to submit the form using Enter key, and the Backspace to..., you got the idea. Just add them into the condition.
@ShouryaSharma, I am not sure if this works on android. In case it doesn't work, just do some test to find the keyCode of the Up and Down key, then put them in the condition statement.
it doesn't matter if the keys don't work as I require the spinners to work in node-webkits' kiosk mode (without keyboard).
|
0

use Javascript

document.getElementById("myId").addEventListener("keydown", function(e){

    e.preventDefault();

})

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.