Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim Function Results

I have a function that returns values from a database. My issue: the function adds "" on the return values. I need to trim the values before displaying them on the user's screen.

This is my function

 <script language="JavaScript" type="text/javascript">
    function handleProcedureChange(procedureid)
    {
        procedureid= document.form1.procedure.value;
        //alert(procedureid);
        var url ="some URL goes here"; 
        url=url+"ProcedureID="+procedureid;

        $.get(url, function(procedureResult) {
            $("#procedureDescription").text(procedureResult);
        });
    }
   </script>

The prcedureResult is the value being returned and the one I need to trim from the quotes before displaying it.

like image 489
Geo Avatar asked May 30 '26 08:05

Geo


1 Answers

Use this to remove quotes :

$.get(url, function(procedureResult) {
     procedureResult = procedureResult.replace(/^"+|"+$/g, "");
     $("#procedureDescription").text(procedureResult);
});

This replaces " from the start (^) and end ($) of the string with nothing ("")

like image 67
Manse Avatar answered Jun 01 '26 20:06

Manse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!