Initialize a string.

Initialize a string.

Hi to all.
I have a problem with a js function where I use a string to import some values from a dropdown list (dataGiusti).
It works fine at the first execution. If I need to execute it again the string contains the preview values.
When I reload the page it works fine againg, but just the first time.

This is my function:
<script type="text/javascript">
var dG = '';
function salvaGiustificazione(arg1) {   
   
    var x1 = document.getElementById('dataGiusti');
    for (var i = 0; i < x1.length; i++)
    {
        if (dG == '')
        {
            dG = [[x1[i].text]];
        }else{                 
            dG =  dG + ', ' + [[x1[i].text]];
        }
    }
   
   
}
</script>

Thanks in advance.

Tegatti