Different values and number formatting with jQuery
I have an input:
<i开发者_Python百科nput type="text" name="number" />
I want show the value for example "79798779" as "797.987,79" but post the value as "797987.79". I am using this plugin for formatting value. How can I change the value in post?
Thanks in advance
You'll have to change the value in your submit handler:
$('form').submit()
{
var $field = $(this).find('[name=number]');
$field.val(
$field.val().replace(/\./, '').replace(',', '.');
);
});
The fastest way is to do this manualy (I think).
HTML:
<form onsubmit="onFormSubmit()" ... > ... </form>
JS:
String.prototype.replaceAll = function (from, to) {
return this.split(from).join(to); // string replace-all-trick
};
function onFormSubmit() {
var value = $('#yourInput').val();
var changedValue = value.replaceAll('.', '').replace(',', '.');
$('#yourInput').val(changedValue);
}
精彩评论