将变量传递给symfony和jquery中的字符串

I want to pass the id into a string but always I get an error

  var c = document.getElementById("predefinedMessage");
    var id= c.selectedIndex;
    var text= "{{  form.predefinedMessage.vars.choices[id].data.message }}";

    $('message').val(text);

});

how I can pass the id in the text variable

If the element that you're selecting is a drop down list, I suggest the following code using jQuery as you're already using it:

// Select by the ID predefinedMessage
var dropDown = $("select#predefinedMessage");

// Get the selected index from the dropdown
var selectedIndex = dropDown.find("option:selected").index();

var text = "{{  form.predefinedMessage.vars.choices[" + selectedIndex + "].data.message }}";

$('message').val(text);