[英]Not Able to retrieve value from specific row <logic:iterate>
I am iterating over a list and displaying value using bean:write, i am using a onfocus event to capture my row details and using 我正在遍历列表并使用bean显示值:write,我正在使用onfocus事件来捕获我的行详细信息并使用
code something like this : 代码是这样的:
<logic:iterate id="empList" name="search" property="empList" indexId="index">
<tr>
<td>
<span id="empid"><bean:write name="empList" property="empID"/></span>
</td>
<td>
<bean:write name="empList" property="firstName"/>
</td>
<td>
<bean:write name="empList" property="lastName"/>
</td>
<td>
<html:button property="View" value="View" onfocus="viewPage()"/>
</td>
</tr>
</logic:iterate>
<script>
function viewPage(){
var empid = document.getElementByID("empid).innerHTML;
}
</script>
but i am not able to get empid value in my javascript variable Please help 但我无法在我的javascript变量中获得empid值请帮忙
It seems you used a wrong function name , it is getElementId()
the d should be in smaller case and also you didn't closed the double quotes. 看起来你使用了一个错误的函数名,它是getElementId()
, d应该是更小的情况,你也没有关闭双引号。
Use this 用这个
var empid =document.getElementById("empid").innerHTML;
https://jsfiddle.net/cLL70bmq/ https://jsfiddle.net/cLL70bmq/
set indexed="true" each field and take form elements to fetch values to the JS set indexed =“true”每个字段并使用表单元素来获取JS的值
<html:form action="something">
<logic:iterate id="empList" name="search" property="empList" indexId="index">
<tr>
<td>
<span id="empid"><html:text name="empList" property="empID" styleId="empId" indexed="true"/></span>
</td>
<td>
<bean:write name="empList" property="firstName" indexed="true"/>
</td>
<td>
<bean:write name="empList" property="lastName" indexed="true"/>
</td>
<td>
<html:button property="View" value="View" indexed="true" onfocus="viewPage(<bean:write name='index'/>)"/>
</td>
</tr>
</logic:iterate>
</html:form>
and update your JS with 并用。更新你的JS
<script>
function viewPage(x){
var empid = document.forms[0].empId[x].value;
}
</script>
hope this helps you 希望这能帮助你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.