Home > OS >  convert decimal value from database into autonumeric in input value when edit
convert decimal value from database into autonumeric in input value when edit

Time:11-05

Hello i've been trying to call my decimal value from my database and put it back into autonumeric with thousand separator value when user tried to edit it, here for example :

here are the input value when user try to create new order : autonumeric with thousand separator

And here was the input value when user try to edit the order, and the data will be NULL in the database when user submit the value, even with the decimal inside the value : decimal value

It change the value into decimal value from the database, and when user tried to hover the input it completely remove the value like this :

missing value

here is the index.blade.php which is the value is taken from database :

$('body').on('click', '.editMediaOrder', function(){
            var id = $(this).data('id');
            $.get('media-order/' id '/edit', function (data){
                $('#modalHeading').html("Edit Media Order");
                $('#btn-update').val("Update");
                $('#editMediaOrderSubmitButton').val("edit-media-order");
                $('#editMediaOrderSubmitButton').prop('disabled',false);
                $('#editMediaOrderModal').modal('show');
                $('#editMediaOrderModal').modal('hide');
                $('#id_edit').val(data.id);
                $('#nomor').val(data.nomor);
                $('#nomor_reference').val(data.nomor_reference);
                $('#periode_start_edit').val(data.periode_start);
                $('#periode_end_edit').val(data.periode_end);
                $('#category_id').val(data.category_id);
                $('#type_id').val(data.type_id);
                $('#agency_code').val(data.agency_code);
                $('#agency_name').val(data.agency_name);
                $('#advertiser_name').val(data.advertiser_name);
                $('#advertiser_code').val(data.advertiser_code);
                $('#brand_code').val(data.brand_code);
                $('#brand_name').val(data.brand_name);
                $('#version_code').val(data.version_code);
                $('#nett_budget').val(data.nett_budget);
                $('#gross_value').val(data.gross_value);
                $('#nett_cashback').val(data.nett_cashback);
                $('#nett_bundling').val(data.nett_bundling);
                $('#spot').val(data.spot);
                $('#accountexecutive_name').val(data.accountexecutive_name);
                $('#group_id').val(data.group_id);
                $('#userto_name').val(data.userto_name);
                $('#notes').val(data.notes);
                $('#attachment_name').val(data.attachment_name);
            })
        });

i've been trying to using jquery and ajax to create the thousand separator at first but ended up using an autonumeric instead, is there was a way to convert the decimal value from database into autonumeric with thousand separator, so that user wont have to input another value and the database will also recognize it?, thank you for your time, and forgive me if there was an spelling error, thanks again!.

CodePudding user response:

function defineMaskMoney() {
    $('.your input class').maskMoney({thousands: '.', decimal: ',', affixesStay: true});
}

this is for query money format.

number_format($yourprice, 2, ',', '.');

this is for backend format to money.

CodePudding user response:

Been trying to find out myself that in the end i'll ended up using jquery number, which is very helpfull, and i just change some of my input to this in my index.blade.php :

$('#nett_budget').on('input',function(){
            var nettbudget = parseInt($('#nett_budget').val());
            var nettcashback = parseInt($('#nett_cashback').val());
            var nettbundling = parseInt($('#nett_bundling').val());
            var grossvalue = parseInt($('#gross_value').val());
        });

and :

$(function(){

        $('#nett_budget').number(true);
        $('#nett_bundling').number(true);
        $('#gross_value').number(true);
        $('#nett_cashback').number(true);

    });

thanks again for helping me, and your time for reading my question.

  • Related