修剪功能结果

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.

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 ("")

Try the following function which will strip off all leading and trailing quotes from a string value

function stripQuotes(str) {
  str = str.replace(/^\"*/, '');
  str = str.replace(/\"*$/, '');
  return str;
}

It can be used as so

$.get(url, function(procedureResult) {
  procedureResult = stripQuotes(procedureResult);
  $("#procedureDescription").text(procedureResult);
});