开发者

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜