如何在jsp中访问动态创建的文本框
我正在尝试创建自己的网格视图。在这里,我从数据库检索食物并将其存储到动态创建的表中。这些表有很多行,所有行都有一个文本框来输入特定项目的数量。我希望仅在选中该复选框时启用此文本框。
这段代码怎么做。
我用了一整天的时间来寻找这个问题的答案。我是j2ee应用程序的初学者。 请帮我。
请建议一些站点来查找可访问和可编辑的数据网格示例的脚本。
该jsp页面的代码如下:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html> <head><title>orderSample</title>
<script language="JavaScript"> <!--
function enable_text(status,i) { status=!status; document.orderForm.NAME_TEXT('i').disabled
= status;///////here is the problem. how to insert i here . i want to do something like this//// } //--> </script>
</head>
<body bgcolor="white">
<form method=post name=orderForm>
<h1>Data from the table 'item details' of database 'caffe' in sql </h1>
<% ResultSet r=null; r=(ResultSet)request.getAttribute("message"); System.out.println(r); int i = 0; %>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;"> <TR>
<TD>ORDER ID</TD>
<TD>ORDER PRICE</TD>
<TD>Quantity</TD>
<TD>Add Item</TD>
</TR>
<%do{
System.out.println("I am in Ob");
%>
<TR>
<TD><%=r.getString(1)%></TD>
<TD><%=r.getString(2)%></TD>
<!-- <td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" IsEnabled="{Binding ElementName=checkBox1, Path=IsChecked}"/></td>-->
<td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" /></td>
<td><input type="checkbox" name="others<%=i%>" onclick="enable_text(this.checked,<%=i%>)"
></td>
</TR> <%i++; }while(r.next()); %>
</TABLE>
</form>
</body>
</html>
I am trying to create my own grid view. here I retrieve the food items from db and store it into a dynamically created table. these tables has a many row and all the row has a text-box to enter the quantity of the Particular Item. I want this text box to enable only when the check box is checked.
How to do this code.
I used this full day in searching answer for this. I am a beginner of j2ee application.
Please help me.
Please suggest some sites to find the scripts for accessible and editable data-grid samples.
The codes of that jsp page is as follows:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html> <head><title>orderSample</title>
<script language="JavaScript"> <!--
function enable_text(status,i) { status=!status; document.orderForm.NAME_TEXT('i').disabled
= status;///////here is the problem. how to insert i here . i want to do something like this//// } //--> </script>
</head>
<body bgcolor="white">
<form method=post name=orderForm>
<h1>Data from the table 'item details' of database 'caffe' in sql </h1>
<% ResultSet r=null; r=(ResultSet)request.getAttribute("message"); System.out.println(r); int i = 0; %>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;"> <TR>
<TD>ORDER ID</TD>
<TD>ORDER PRICE</TD>
<TD>Quantity</TD>
<TD>Add Item</TD>
</TR>
<%do{
System.out.println("I am in Ob");
%>
<TR>
<TD><%=r.getString(1)%></TD>
<TD><%=r.getString(2)%></TD>
<!-- <td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" IsEnabled="{Binding ElementName=checkBox1, Path=IsChecked}"/></td>-->
<td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" /></td>
<td><input type="checkbox" name="others<%=i%>" onclick="enable_text(this.checked,<%=i%>)"
></td>
</TR> <%i++; }while(r.next()); %>
</TABLE>
</form>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用 JavaScript 在同一表行中使用复选框启用输入文本字段,最简单的方法是获取 jQuery。
首先,为表行中的复选框和输入字段指定类名。
然后,您可以使用 jQuery
这基本上告诉每个带有
class="add"
的复选框,当单击它时,它应该查找最接近的父元素,然后找到该元素与
class="quantity"
,然后将其disabled
属性设置为与复选框的选中状态相反。To enable a input text field using a checkbox in the same table row using JavaScript, it's the easiest to grab jQuery.
First, give the checkboxes and input fields in table rows a classname.
Then, you can use jQuery
This basically tells every checkbox with
class="add"
that when clicked it should lookup the closest parent<tr>
element and then locate the element withclass="quantity"
and then set itsdisabled
attribute with the opposite of the checked state of the checkbox.