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

时间:2015-10-07 13:55:47

标签: php jquery symfony

我想将id传递给字符串,但总是会出错

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

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

});

我如何在文本变量中传递id

1 个答案:

答案 0 :(得分:0)

如果您选择的元素是下拉列表,我建议您使用jQuery以下代码:

// 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);