Re: How to format textbox value before sum?



staeri@xxxxxxxxx said the following on 3/14/2006 7:55 AM:
I'm grateful for the answers but they none of them are working on my
system. One textbox contains for example the value "2 100". This should
be treated as "2100" but is treated like "NaN".

Maybe it's easier to say that space, dot or comma should be eliminated.

<input onchange="
this.value=this.value.replace(/\./g,'').replace(/\,/g,'').replace(/\ /g, '');"

Will remove any commas, any dots and any spaces from the input. Test it :)

And if the user by mistake writes anything else than numbers it should
be treated like "0" so that they always get a correct sum.

So, if I type in "Randy Webb" instead of 123, it should deduce that I meant 0? Test it for all digits after removing spaces commas and periods. Then, if it contains non-digits you tell the user they have incorrect input.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
.



Relevant Pages

  • Re: How to format textbox value before sum?
    ... Will remove any spaces, commas or periods (dot). ... jscr maths, dates, sources. ... TP/BP/Delphi/jscr/&c, FAQ items, links. ...
    (comp.lang.javascript)
  • Re: TextBox ControlSource
    ... dans le message de news: ... > Ignore the fact that I'm using commas and you're using semi-colons, ... >> I have to set the control source of a textbox and I use the ...
    (microsoft.public.access.formscoding)
  • Re: Scan frequencies for a Sony KV-20S20
    ... the EU prefers commas to delimit decimals. ... God only ... What is wrong with a dot, ...
    (sci.electronics.repair)
  • Re: Default value for multi-select list box
    ... MOGSY wrote: ... get the selected items which are being displayed in the textbox to be ... displayed as a list, instead of using commas? ...
    (microsoft.public.access.forms)
  • Re: Textbox calculation problem...
    ... it is because of using commas. ... the commas for dots for the purposes of calculating. ... I have a little textbox problem. ... Private Sub TextBox1_Exit ...
    (microsoft.public.excel.programming)

Loading