Anda di halaman 1dari 2

 

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>
Honestly, this approach is definitely not MVC2. With MVC2 the JDBC code goes in its own Java DAO class, the
model goes in its own Javabean class, the HTTP request/response is controlled by a Java Servlet class and the JSP file
1  contains only HTML/JS code, along with taglibs/EL. – BalusC Mar 12 at 19:10
this is the very first application page i am making.. i was in .net before . there we had a dragDrop option for data grid..
Can u please suggest me to complete my task in JSP using eclipse – user238284 Mar 12 at 19:11
You're talking about ASP.NET MVC? The Java counterpart is JSF, not JSP with scriptlets and all other concerns
1  mingled. – BalusC Mar 12 at 19:13
k my friend, i give up.i am very sorry for my misunderstanding. Can u suggest some site links or examples to solve
my problem – user238284 Mar 12 at 19:17
If you want to do the same in Java as you did in ASP.NET MVC, then invest time in JSF, not JSP. JSF offers
the <h:dataTable> as equivalent to ASP.NET MVC's dataGrid. – BalusC Mar 12 at 19:41

1 Answer
activeoldestvotes

up To enable a input text field using a checkbox in the same table row using JavaScript, it's the easiest to grab jQuery.

2
vote dow
First, give the checkboxes and input fields in table rows a classname.

n vote <td><input type="checkbox" class="add" /></td>


accepted

<td><input type="text" class="quantity" /></td>

Then, you can use jQuery

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    $(document).ready(function() {
        $('.add').click(function() {
            $(this).closest('tr').find('.quantity').attr('disabled', !this.checked);
        });
    });
</script>

This basically tells every checkbox with class="add" that when clicked it should lookup the closest
parent <tr> element and then locate the element with class="quantity" and then set itsdisabled attribute
with the opposite of the checked state of the checkbox.
link|edit|flag

Anda mungkin juga menyukai