0

I set the value that user input to database to become lowercase letter so when I retrieve it back to show in my database table it will be lowercase as well and I want to make the first letter of that word become capital.Example when the user choose the status as Active,the value it will convert it to active in my database but when it retrieve back I want it to be Active on the table ui instead of active. Here is how I get the value from the database:

    function getSearchRequest(offset) {
        var serachVal=$('#search').val();

        // alert(offset);
        $.ajax({

            url : '${createLink(action:'searchCustomerJSON')}',
            type : 'GET',
            data : {
                'search' : $('#search').val(),
                'offset':offset
            },
            dataType:'json',
            success : function(data) {
                var tableHtml='';
                var i=1;
                var pages=data.pages;
                // alert(pages);
                if(changed) {
                    offset=0;
                    $('#pagination-div').html('<ul id="pagination-demo" class="pagination-sm" style = "background-color:transparent;font-weight: bold;border:none!important;-webkit-box-shadow: none"></ul>');
                    $('#pagination-demo').twbsPagination({
                        totalPages: pages,
                        visiblePages: 7,
                        onPageClick: function (event, page) {
                            offsetVal = (page - 1) * 10;
                            getSearchRequest(offsetVal);
                        }
                    });
                    changed=false;
                }
                if(prevValue!=serachVal)
                {
                    changed=true;
                    prevValue=serachVal;
                }
                for(index in data.customers)
                {
                    var tableData=data.customers[index];
                    var id=tableData.id;
                    var code=tableData.code;
                    var contactPerson=tableData.contactPerson;
                    if(!contactPerson)
                    {
                        contactPerson='';
                    }
                    var status=tableData.status;
                    var name=tableData.name;
                    tableHtml+='<tr style = "LINE-HEIGHT:42px">' +
                        '<td>'+(i+offsetVal)+'</td>' +
                        '<td id ="link"><a style = "color:black;text-decoration:none;"href="${createLink(action: 'showCustomerClientById')}/'+id+'">'+name+'</a></td>' +
                        '<td>'+code+'</td>' +
                        '<td>'+contactPerson+'</td>' +
                        '<td>'+status+'</td>' +
                        '<td id ="link" style="text-align:center"><a style="color:black;text-decoration:none;" href="${createLink(action: 'showCustomerById')}/'+id+'"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>&nbsp; &nbsp;<a style="color:black;text-decoration:none;" href="${createLink(action: 'showCustomerClientById')}/'+id+'"><i class="fa fa-file-text" title="Customer Clients"></i></a></td></tr>';
                    i++;




                }
                $('#tableBody').html(tableHtml);
            },
            error : function(request,error)
            {
                alert("Request: "+JSON.stringify(request));
            }
        });

    }
    getSearchRequest(0);

Many thanks.

PanhaSeav
  • 77
  • 5
  • 1
    `function ucFirst(string){ const s = string.split(''); if(s.length){ s[0] = s[0].toUpperCase(); return s.join(''); } return false; }` – StackSlave Jan 20 '21 at 01:15
  • 2
    Css text-transform capitalize? – Musa Jan 20 '21 at 01:55
  • Does this answer your question? [How do I make the first letter of a string uppercase in JavaScript?](https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript) – Twisty Jan 20 '21 at 02:15

0 Answers0