views:

28

answers:

3

i have one text box formated with follwoing syntax

       $("#cont_dt").blur(function(){
      $(this).format({format:"#,###.00", locale:"us"}); 
        })  

this work fine, for example if i type 250000.50 it automatically formated to

    250,000.50

but the problem is when i try to pass same value to php file via ajax to add record in mysql i got error.

i think i need to bring 250,000.50 again in 250000.50 format to store in mysql.

how can i do this?

Thanks

          **EDIT**

dear all i need ajax / java script function to remove , not php function. thanks for help

+1  A: 

Pass PHP the non-formatted number instead or remove the comma with str_replace(",","", $number).

Artefacto
Shouldn't there be a more 'beautiful' method to do this? One that, for example, doesn't mess up when the locale defines `,` as the decimal separator? (I'm not saying this answer is useless, I'm just wondering...)
MvanGeest
@MvanGeest Since he's explicitly defining the locale in Javascript, you're guaranteed "." is the decimal separator.
Artefacto
@Mvan To respond to the other part of the question, there's numfmt_parse.
Artefacto
@Artefacto: just asking this because SO should be an 'inexhaustible collection of information' 'collaboratively built and maintained by your fellow programmers'... or whatever. The more solutions, the better, I suppose.
MvanGeest
+1  A: 

What is field type of the field your using to store this value in your mysql table?

Using int, double or decimal you'll not be able to store the value with the comma. If you are set on storing the value with the comma, versus just formatting the number upon pulling it out of the table, then you can change the field type to varchar.

kmfk
+1  A: 

simply .format() the element onSubmit

nathan
i try using .fromat i can't suscess because i want to format value of variable before passing...
air