How can I take input in a texbox

23 views
Skip to first unread message

Mayank Pandey

unread,
Oct 16, 2021, 6:29:29 PM10/16/21
to Developing Interactive Simulations in HTML5
Hello,

I am trying to take user input such that they can type a number of their choice and I can process that data to do something with it (after verifying that it is a valid number). Is there a component made my PhET that can be used for this purpose?

cmalley

unread,
Oct 17, 2021, 8:44:23 PM10/17/21
to Developing Interactive Simulations in HTML5
PhET does not currently have a UI component for entering text (or numbers) directly from the keyboard.  There have been several discussions about adding something like this, but (as far as I know) nothing is planned for the short term. 

You might have a look at Keypad.js, which allows you to enter numbers using a numeric keypad. It lives in the scenery-phet repository, with a demo in ComponentsView.js.  There's a good example of using Keypad in the Unit Rates simulation, see KeypadPanel.js in the unit-rates repository.

Chris Malley
PixelZoom, Inc.

cmalley

unread,
Oct 17, 2021, 8:49:01 PM10/17/21
to Developing Interactive Simulations in HTML5
Here's a screenshot of the Keypad demo in scenery-phet repository:

scenery-phet.png

Here's a screenshot of KeypadPanel in unit-rates repository:

unit-rates.png

Reply all
Reply to author
Forward
0 new messages