我的表格中有一个下拉菜单 . 当我在其中选择'other'选项时,会出现一个内部文本框 . 而不是从下拉列表中选择选项,用户更喜欢输入文本 . How can i pass inner html path value(input type=text) entered by the user through path of dropdown menu(input type=select). 我还想要在调用内部html时禁用选择输入 .
这是我的下拉代码
<form:select path="competitorName" name="competitorName" title="Choose a competitor"
onchange="$('#competitor_name').val($.trim($('#myCompetitorId option:selected' ).text()));showfield(this.options[this.selectedIndex].value)"
id="myCompetitorId">
<option value=" ">Please select an competitor</option>
<c:forEach var="competitor" items="${competitors}">
<option
value="<c:out value="${competitor.competitorName}"/>">
<c:out value="${competitor.competitorName}" />
</option>
</c:forEach>
<option value="Other">Other</option>
</form:select>
我的javascript代码
<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='<font size="0">Name</font><input type="text" name="competitorName" path="competitorName"/>;
else document.getElementById('div1').innerHTML='';
}
</script>
1 回答
我不知道你的XML,或者其他什么,但这里有一个可能有用的功能 .
使用外部JavaScript,将
<script>
标记与src
中的src
属性放在一起 . 当然,如果你想使用我的E
函数,你必须将'yourSelectId'
和'yourTextElementId'
更改为正确的id .