0

I need to let users enter molarity units into an HTML input (mM, uM, nM, and pM) instead of long string of numbers to the right of the decimal point. "16pM" is easier to type than .000000000016.

The database will be sending the decimal version to the client, and the client has to send the decimal version back to the database. But the user needs to see the human-friendly format and be able to enter the human-friendly format into the textbox.

I can do the conversions, just not sure of the proper place to do them. Do I have to extend the INPUT's prototype? I'd be grateful if someone could get me started in the right direction with a quick description of what's involved in getting an HTML INPUT to do this kind of bi-directional input/output conversion.

I don't need code, just the proper terminology or a couple of helpful links so I can find my way to the right resources. Thanks

Tim
  • 8,669
  • 31
  • 105
  • 183
  • This isn't a question with a "right" answer -- I've seen sites that do conversions like this as soon as the cursor moves out of the text field (using JavaScript), and others do it server-side out of the user's view. A third approach is to store the converted value in a hidden input, which is populated by JavaScript when the first field is unfocused. Which approach you take is largely up to you and your users. (However, any approach that uses JavaScript runs the risk of being unusable if JS is turned off in the user's browser.) – Blazemonger Sep 20 '13 at 21:05
  • I need to do it client-side. Not saying that's the right way or the wrong way. My main concern is how to make sure the internally stored format is bindable to a viewmodel. – Tim Sep 20 '13 at 21:06

1 Answers1

0

OK, I've found my way to the jQuery widget factory.

http://learn.jquery.com/jquery-ui/widget-factory/how-to-use-the-widget-factory/

Tim
  • 8,669
  • 31
  • 105
  • 183