0

I am trying to do a type of calculator that calculates the Body Mass Index of a person. It works real nice if I input the actual value (I use jQuery to make the calculus).

What I want to do though, is that instead of typing the value, the user to be able to write it from the numbers buttons, so it works like a calculator.

The problem I have is that I can't find how to know if an html input is selected. This is necessary since I will use the same "keyboard" for two different inputs (One to enter weight and another one for height). I put below an image of how it works. Same keyboard for two different inputs.

Image

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Iñigo Zepeda
  • 51
  • 2
  • 8
  • 1
    Does this answer your question? [Using jQuery to test if an input has focus](https://stackoverflow.com/questions/967096/using-jquery-to-test-if-an-input-has-focus) – Nikolaj Dam Larsen Mar 02 '21 at 00:21
  • If you're trying to test one of those boxes up top, to see if the user selected it, just store a value into a higher scoped variable `onclick`. Test for the variable on some other Event of another Element. – StackSlave Mar 02 '21 at 00:24
  • Wait I am confused you want to check an `input element` or ``? –  Mar 02 '21 at 00:40

1 Answers1

0

Problem: I think you are complicating the issue by attempting to use the same keyboard for two inputs. If you want to achieve your goal in this manner, you will need to:

  • add event listener to each input ('click' event)
  • change how the keyboard behave depending on which input is selected (heavy work!)

Solution: Prepare a keyboard for each input.(two keyboards in total) That way, you only have to:

  • display the keyboard for the input selected

You can either use CSS selector or JavaScript to handle displaying the appropriate keyboard. I think it is so much simpler than using 'the same keyboard'.

Kouta Nakano
  • 595
  • 3
  • 15