我正在尝试显示通过flask传递到我的网页的sql表中的行选择。选择哪些行取决于从HTML下拉列表中选择的值(表中的一列是
id
. 我需要id与表单中选定值对应的行):
<form name="dropdownForm" style="padding:10px 0px 0px 20px" onchange="calldropdown(this.value)">
<select name="dropdownselection" id='dropdownresult'>
<option value=1>Option 1</option>
<option value=2>Option 2</option>
<option value=3>Option 3</option>
</select>
</form>
目前,我正在将此表单的结果传递给javascript函数,但到目前为止,我只能显示表单中选定的值,而不是我需要的:
<p id = areatodisplay"></p>
function calldropdown(dropdownresult) {
var result= document.getElementById('dropdownresult').value
document.getElementById("areatodiaplsy").innerHTML = result;
}
innerHTML
行,导致语法错误:
document.getElementById("areatodiaplsy").innerHTML = {% for i in getInfo %} {% if i.id == result %} {{i.name}} {% endif %} {% endfor %};
为了完整起见,我使用的烧瓶代码是:
@app.route('/live')
def live():
return render_template('live.html', getInfo=Info.query.all())