0

I am using Telerik controls in an ASP.Net application for invoice entry.

I'm looking for the ability to enter multiple amounts in one numeric field and add them together, just like in Quickbooks.

Keystrokes:

=0.12+3.45TAB or ENTER

adds values to 3.57 and jumps to the next field.

Anyone has any ideas?

dtb
  • 213,145
  • 36
  • 401
  • 431
larryr
  • 1,536
  • 3
  • 17
  • 27
  • 1
    I'm not familiar with the Telerik controls here, but a JS math parser might be just as good in this case: http://stackoverflow.com/questions/3936730/javascript-math-parser-library – keyboardP Aug 10 '11 at 16:10

2 Answers2

1

You have three choices here:

  1. Write your own method to parse the formula (more complicated than it sounds, even if you think it sounds complicated).
  2. Use an pre-written math parser. This is a decent one.
  3. Use eval().

NOTE: Should you choose option #3, exercise extreme caution and do your research first. eval() can leave your application open to all sorts of nasty code injection.

Community
  • 1
  • 1
James Hill
  • 60,353
  • 20
  • 145
  • 161
  • Code injection bad, however the Eval() route can be made much safer by first RegEx-ing the text string to only allowable characters. – EtherDragon Aug 10 '11 at 17:00
-1

You'll need to build a lexical parser for in-fix (rather than prefix) notation. There should be plenty of examples around - it's a pretty standard concept used on a lot of degree courses.

As to whether it's a good idea to do this (I assume client-side)...

Dave
  • 3,581
  • 1
  • 22
  • 25