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>
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 itsdisabledattribute with the opposite of the checked state of the checkbox.