开发者

Different values and number formatting with jQuery

开发者 https://www.devze.com 2023-04-04 14:23 出处:网络
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

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

精彩评论

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