2

I have this code

<input name="mpan[]" value="" maxlength="2" size="2">
<input name="mpan[]" value="" maxlength="2" size="3"> 
<input name="mpan[]" value="" maxlength="2" size="3">
<input name="mpan[]" value="" maxlength="2" size="12">

What I have to do is I am provided with a large key for example 0380112129021. When I do Ctrl+C on that key and select any box and press Ctrl+V, the number automatically get pasted in different box, for example: first input box gets 03, next gets 801, next gets 112 and rest gets pasted on last one 129021.how do i achive this from javascript

4
  • @rlb.usa: How to achieve this in JS, I suppose. Commented Jun 16, 2010 at 18:46
  • Does it need to be Ctrl+C and Ctrl+V? Commented Jun 16, 2010 at 18:47
  • 2
    Btw: your maxlength doesn't comply with required input lengths. You now have 4 input elements where you can input max 2 characters. Maybe you want to swap it with the size or align the values to be the same? Commented Jun 16, 2010 at 18:50
  • Retrieving the pasted text requires browser-specific code; I don't know off-hand of any framework that normalizes that, but I'd like to :-) Commented Jun 16, 2010 at 18:58

3 Answers 3

1

If you're looking to catch paste events (rather than the literal Ctrl+V), the onpaste event may be for you, and is supported by most browsers according to this answer.

The splitting of the input value you could do using substring().

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

1 Comment

He's also going to have to get the data from the paste - in other words, the clipboard contents. That doesn't seem to be standardized across browsers, as far as I can tell.
0

Easy. On each of the input box, add an onkeyup handler and inspect the input values.

Little clarification, you're trying to do something like serial/key input boxes, right?

3 Comments

By using onmouseup? s/he can use the same function for the different events.
There's also pasting from the Edit menu to consider, or by dragging.
In that case there's onchange. Or you could (in extreme cases) run a timer. For the dragging case, I'm sure onmouseup captures it.
0

okay if you have no idea you should read through some stuff.

i can recommend to read about

  • javascript - events.
  • especialy the onkeyup/onkeydown events
  • stringparsing (substring)

after that you will see the answer glowing on your screen ;-)

a little hint: if you store the pressed keys to a variable, it should be cleared after the action is triggered. and you should check what you have in you keypress cache and clear illigal input.

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.