-1

hopefully someone can help with jquery numpad. The problem is that when you click on the input field and you click on the numbers, than the code is dublicating. I mean there is two input fileds and when you type then the numbers are dublicating into the other input field. Please check Fiddle, thank you for your help.

  • [FIDDLE](https://jsfiddle.net/ffshgn6g/) link. – Timár Csaba Apr 01 '16 at 11:43
  • You are using the class instead of a unique id when adding values to the input, switch to using an ID or other unique property. Because both inputs have the same class the value will be assigned to both – Bart Apr 01 '16 at 11:46
  • Thanks for your reply. Unfortunatly i changed the id's and it has the same problem – Timár Csaba Apr 01 '16 at 11:59
  • If you have a problem with your code, then you should post it here (you can [edit] your question). A jsfiddle link is not sufficient, because links break all the time and your question will lose all value for future readers in that case. – Artjom B. Apr 01 '16 at 12:21
  • https://jsfiddle.net/ffshgn6g/10/ updated your fiddle.. I added the lastfocused element to be updated when numpad is used. Your $('.numero').click was duplicated and again caused the issue where the value was added to both inputs – Bart Apr 01 '16 at 12:22
  • @Bart thank you very much :) – Timár Csaba Apr 01 '16 at 12:23
  • @Bart - Nice solution, add as an answer and accept it Timár! – urbz Apr 01 '16 at 12:24

1 Answers1

1

Add the following which sets the element to a var to be used when a number is clicked:

var lastFocused;
$('input').on('focusin', function() {
   lastFocused = $(this);
});

On all the id selectors replace with $(lastFocused) to set/delete/clear the last focused inputs values.

Updated Fiddle: https://jsfiddle.net/ffshgn6g/15/

urbz
  • 2,663
  • 1
  • 19
  • 29
Bart
  • 432
  • 4
  • 12
  • Hi @Bart, i updated my fiddle but there is one more thing if you could help me with please. If I want to use letters than the code stops. The new fiddle is on the same link. Thank you for your help! – Timár Csaba Apr 04 '16 at 07:57
  • Hi @TimárCsaba, the issue is with the `isNaN` check, when you add letters the value becomes `NaN` and the rest of the code will not execute – Bart Apr 04 '16 at 08:07
  • Good :) thank you now it works, thanks again! – Timár Csaba Apr 04 '16 at 08:13
  • Hi @Bart. Sorry to bother u again but I have a last issue, I tryed everything but my javascript knowledge is not good. Hope you can help me with one last thing. I updated the code again in fiddle. The problem is with the code that when I click on the shift key at the bottom left the text on the keybord transforms to capital letters but in the input fileds I have the same lowercase letters. Hope I dont ask to much :) Thank you! – Timár Csaba Apr 04 '16 at 13:49
  • Hi @TimárCsaba when you add the class `upper` it only changes the appearance of the letters and not the actual values. I have updated your fiddle here : https://jsfiddle.net/ffshgn6g/26/ Added an `isUpper` variable which is set when shift is clicked to determine whether an upper or lowercase character should be used – Bart Apr 04 '16 at 14:05
  • HI @Bart I dont know how can I give reputation but you rock, pls let me know if I can do something for you :) thanks! – Timár Csaba Apr 04 '16 at 14:09