我想从列表中循环选定的数字(cfselect)。我尝试了getElementById但只能在同一页面上显示它。我无法将此数字传递给循环。有人能帮我吗?谢谢。
function item()
var a = document.formName.numList.selectedIndex;
document.getElementById('i').value = document. family.tBro.options[a].value;
var n=document. family.tBro.options[a].value;
<!----OTHER INPUT TEXT BOXES --->
<cfform name="family" action="complete.cfm" method="post">
How many brothers do you have?
<cfselect name="tBro" onChange="item();" required="yes">
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4">4</option>
</cfselect>
<!---DISPLAY THE SELECTED CHOICE from getElementById--->
Total number of brothers: <cfinput type="text" name="i" id="i">
<!---LOOP x amount of time from selected choice above.
For example, if 2 is selected, the below info will display two times
--->
<cfinput type="text" name="firstname" required="yes">
<cfinput type="text" name="lastname" required="yes">
<cfinput type="text" name="Age" required="yes">
<cfinput type="text" name="Ocupation" required="yes">
<!--- END LOOP--->
答案 0 :(得分:5)
提示:陈述您要完成的任务,而不是实施。我不得不重读几次以了解你的需求,在这种情况下你的实现并不是很合适。
您正在尝试将JavaScript传递给CFM代码:这不是它的工作方式。 ColdFusion在服务器上呈现; JavaScript在客户端上呈现。在调用item()时,ColdFusion已完成所有渲染;你不能用item()的结果来影响CF循环。
如果没有真正复杂的AJAX解决方案,您有两种选择: