[英]how to pass path and value of inner html input type to path of main input type in <form>?
I have a drop down menu in my form. 我的表格中有一个下拉菜单。 When I select 'other'option in it an inner text box appears.
当我在其中选择“其他”选项时,会出现一个内部文本框。 Instead of selecting the option from the dropdown user prefers to enter the text.
而不是从下拉列表中选择选项,用户更喜欢输入文本。 How can i pass inner html path value(input type=text) entered by the user through path of dropdown menu(input type=select).
如何通过下拉菜单的路径(输入类型=选择)传递用户输入的内部html路径值(输入类型=文本)。 And i also want that when inner html is invoked the select input should be disabled.
我还想要在调用内部html时禁用选择输入。
here is my dropdown code 这是我的下拉代码
<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>
My javascript code 我的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>
I don't know about your XML, or whatever that is, but here's a function that might help. 我不知道你的XML,或者其他什么,但这里有一个可能有用的功能。
//<![CDATA[
function selectToText(selectElement, textElement){
selectElement.onchange = function(){
if(textElement.value){
textElement.value = this.value;
}
else{
textElement.innerHTML = this.value;
}
}
}
var pre = onload, doc, bod, htm, E;
onload = function(){
if(pre)pre();
doc = document, bod = doc.body, htm = doc.documentElement;
E = function(id){
return doc.getElementById(id);
}
selectToText(E('yourSelectId'), E('yourTextElementId'));
}
//]]>
Use external JavaScript, putting the <script>
tag with a src
attribute in your <head>
. 使用外部JavaScript,将
<script>
标记与<head>
的src
属性放在一起。 Of course, you have to change 'yourSelectId'
and 'yourTextElementId'
to the proper id's if you want to use my E
function. 当然,如果你想使用我的
E
函数,你必须将'yourSelectId'
和'yourTextElementId'
更改为正确的id。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.