tags:

views:

60

answers:

3

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

A: 

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?

Christian Sciberras
What if the user pastes content using right-click > paste?
Pekka
By using onmouseup? s/he can use the same function for the different events.
Christian Sciberras
There's also pasting from the Edit menu to consider, or by dragging.
Tim Down
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.
Christian Sciberras
A: 

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.

helle
+1  A: 

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().

Pekka
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.
Pointy