0

I am building my own context menu and am replacing copy / cut / paste functionality. I have copy and paste working but I cannot paste arbitrary text into an input of type 'number'.

I am setting the value using javascript similiar to below

document.getElementById('input').value = 'some text'; 

Whenever type is of number, the text is lost and the input is left blank.

Can I set the input to a string? The system paste allows this, but the input seems to parse the input and fail.

Obligatory jsfiddle

3
  • So, set the input type to text otherwise there's no any idea... Commented Dec 16, 2014 at 23:53
  • Yeah why have the input as number? To me it makes more sense as text since you can also place numbers into that. If there is more too this or a reason why you need number let me know. Commented Dec 16, 2014 at 23:55
  • An input of type 'number' only allows numeric input. If your string happens to parse as a valid number, then the paste will work fine, but you simply can't put a text value in a number field. Commented Dec 16, 2014 at 23:55

1 Answer 1

2

You can change

<input id="input" type="number" value="1"></input>

to

<input id="input" type="text" value="1"></input>

Or change it in your javascript by adding

document.getElementById('input').setAttribute('type','text')

in your setText() function

jsFiddle: Here is the resulting jsFiddle

Sign up to request clarification or add additional context in comments.

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.