Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
Track Cursor Location OnClick Phone/Dial Pad (React)

I'm trying to implement an on screen phone that takes input from either the keyboard, or from clicking on the numbers on screen.

enter image description here

The input field already works for key down implementations (typing 1 2 3 ....) naturally and where the cursor is (likely from .selectionStart). I'm having an impossible time tracking cursor position when I click on the on screen keyboard. I have tried quite a few different implementations but the current one is:

<input 
  type="text" 
  className="phone-pad-input" 
  id="phone-input"
  onChange={(e) => handleKeypress(e)}
  onFocus={(e) => {e.target.selectionStart = props.cursorPosition}} // coded this last week forget if it even works or does anything
  autoFocus={true} // I want the phone's input focused 100% of the time it's up
  autoComplete="off"
  onBlur={({ target }) => target.focus()}
  value={props.number}>
</input>

My screen key pad is a table where each number is:

<td className="..." onClick={() => handleKeyClicked(#)}></td>

Function for the handleKeyClicked:

const handleKeyClicked = (num: any) => {
  const phoneKeyPad = document.getElementById('phone-input')
  const cursorPosition = (phoneKeyPad as HTMLInputElement).selectionStart 
  console.info("CURSOR POS:", cursorPosition) // this is ALWAYS 0
  // ... logic to put my number in the correct spot with slicing based on cursorPosition
}

Is there any way to grab the .selectionStart from this onclick on the phone pad? If my value is: 1245 and I have my cursor (blinking) between the 2 and 4. I hit the "3" it still says cursor position is 0 and will either append or prepend depending how I coded it. I opened up Google Voice for the sake of testing their phone, and it also appends the numbers (12453) regardless of cursor position.

Thanks for any assistance

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!