稍微挣扎以确定从下拉列表中选择了哪个项目(或没有项目)(HTML / javascript)
目前有(正确填充下拉列表)
<select name="typeselected" id="typeselected" onchange="typeselected();">
<option value="">-- Please select --</option>
<sql:query var="queryresults" dataSource="jdbc/database">
SELECT id, name from assettype order by name
</sql:query>
<c:forEach var="row" items="${queryresults.rows}">
<option value="<c:out value="${row.id}" />"
<c:if test="${ row.id == param.id }">
selected
</c:if>
>
<c:out value="${row.name}" />
</option>
</c:forEach>
</select>
当前typeselected()函数(这也有效) -
function typeselected()
{
if(document.getElementById("typeselected").selectedIndex == 0)
{
assetselected = "'%'";
alert(assetselected);
}
else
{
assetselected = document.getElementById("typeselected").value;
alert(assetselected);
}
}
我想在单独的sql:query中使用所选的id(在变量&quot; assetselected&#39;中)。
我试过了
where assetypeid = (assetselected)
where assetypeid = ${assetselected}
where assetypeid = '${assetselected}'
where assetypeid = document.getElementById("typeselected").value
但没有任何作用(选择无法产生任何记录)
任何帮助(使用正确的sql语法/命令)都很感激。
此致 拉尔夫