Problem with selecting Check box in a jsp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chindanoor
    New Member
    • Apr 2007
    • 13

    #1

    Problem with selecting Check box in a jsp

    I have a JSP page that dynamically lists records in a table from my database. At the left hand side of each row in the table, there are checkboxes for the user to select a particular record that he/she wants to do manipulation. Here we are showing 100 records per page and user can go to next page in which it will show one more hundred records(ie 101 to 200)..As now the problem is when user has select the particular record in Page 1 and when go to Page 2 and if he come back to page 1 the selected paritcular is not checked.... how make it to selected...
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #2
    Originally posted by chindanoor
    I have a JSP page that dynamically lists records in a table from my database. At the left hand side of each row in the table, there are checkboxes for the user to select a particular record that he/she wants to do manipulation. Here we are showing 100 records per page and user can go to next page in which it will show one more hundred records(ie 101 to 200)..As now the problem is when user has select the particular record in Page 1 and when go to Page 2 and if he come back to page 1 the selected paritcular is not checked.... how make it to selected...
    keep an array of selected checkbox ids, and other info if needed in the session. whenever you go to any page check for the checkbox id, if exists then check it else let it be unchecked.

    Comment

    • anilraghuvanshi
      New Member
      • Jul 2007
      • 4

      #3
      Originally posted by chindanoor
      I have a JSP page that dynamically lists records in a table from my database. At the left hand side of each row in the table, there are checkboxes for the user to select a particular record that he/she wants to do manipulation. Here we are showing 100 records per page and user can go to next page in which it will show one more hundred records(ie 101 to 200)..As now the problem is when user has select the particular record in Page 1 and when go to Page 2 and if he come back to page 1 the selected paritcular is not checked.... how make it to selected...

      Hi,

      You can do one thing also. Whnever you move from one page to another put ids of the selected checkboxes in a temp table and then everytime fetch the ids at every page to make checkboxes checked.

      After finishing this operation delete data from that table.

      Regards,

      Comment

      • oyis
        New Member
        • Jul 2007
        • 8

        #4
        Originally posted by chindanoor
        I have a JSP page that dynamically lists records in a table from my database. At the left hand side of each row in the table, there are checkboxes for the user to select a particular record that he/she wants to do manipulation. Here we are showing 100 records per page and user can go to next page in which it will show one more hundred records(ie 101 to 200)..As now the problem is when user has select the particular record in Page 1 and when go to Page 2 and if he come back to page 1 the selected paritcular is not checked.... how make it to selected...
        Hi,
        I have a JSP page same as yours.
        I can select the checkbox but I can't get the values...
        I want to select the checkbox and it gives me value of data.
        all things must be dynamically.
        please helppp me :(

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by oyis
          Hi,
          I have a JSP page same as yours.
          I can select the checkbox but I can't get the values...
          I want to select the checkbox and it gives me value of data.
          all things must be dynamically.
          please helppp me :(
          Can you be more specific about your problem? Where are you failing to get the value?

          Comment

          • oyis
            New Member
            • Jul 2007
            • 8

            #6
            Originally posted by r035198x
            Can you be more specific about your problem? Where are you failing to get the value?
            ı think , if I sent my code you can understand easily;

            create table function;


            var tbody = document.getEle mentById('t1'). getElementsByTa gName('tbody')[0];
            var row = document.create Element('TR');
            var cell1 = document.create Element('TD');
            cell1.innerHTML = myA[i];
            var cell2 = document.create Element('TD');
            cell2.innerHTML = myB[i];
            var cell3 = document.create Element('TD');
            var checkBox = document.create Element('INPUT' );
            checkBox.setAtt ribute("type", "checkbox") ;
            cell3.appendChi ld(checkBox);
            checkBox.checke d = false;

            row.appendChild (cell1);
            row.appendChild (cell2);
            row.appendChild (cell3);
            tbody.appendChi ld(row);


            i want to select one or more row to delete from table.
            and i want to know which row is selected when i check the checkbox ...
            may i explain now?

            Comment

            • sumittyagi
              Recognized Expert New Member
              • Mar 2007
              • 202

              #7
              Originally posted by oyis
              ı think , if I sent my code you can understand easily;

              create table function;


              var tbody = document.getEle mentById('t1'). getElementsByTa gName('tbody')[0];
              var row = document.create Element('TR');
              var cell1 = document.create Element('TD');
              cell1.innerHTML = myA[i];
              var cell2 = document.create Element('TD');
              cell2.innerHTML = myB[i];
              var cell3 = document.create Element('TD');
              var checkBox = document.create Element('INPUT' );
              checkBox.setAtt ribute("type", "checkbox") ;
              cell3.appendChi ld(checkBox);
              checkBox.checke d = false;

              row.appendChild (cell1);
              row.appendChild (cell2);
              row.appendChild (cell3);
              tbody.appendChi ld(row);


              i want to select one or more row to delete from table.
              and i want to know which row is selected when i check the checkbox ...
              may i explain now?

              Your code is unmanaged.
              Whether you code in any language, the rule is to first analyze your problem then go for coding.

              The solution to your problem is to maintain a counter, and give name to your controls according to that counter.

              If there are 4 rows already displayed(accor ding to the records in the database), and according to some mainpulation more rows could be added. Then initialize your counter to 4. and with each manipulation increment the counter accordingly.

              for eg. you are having a checkbox, a txtbox and a selectbox each row.
              Then these could be named as chkABC0, chkABC1..., txtABC0, txtABC1,... , selABC0, selABC1....
              here 0, 1, 2... are appended to the controls according to the counter.
              so chkABC0, txtABC0, selABC0 belongs to the first row.

              I think you would have got the point.

              And remember, always keep in mind how you will extract an information before storing it. I noticed you havn't given any name or id to your checkboxes. How will you be able to get the reference of those checkboxes for manipulation.

              Second thing is you should think of a better way of retriving information while checking for alternatives.
              eg. you gave ID to your table, and then from that table extracted an array of tbody elements, and selected first element from that array.
              You could have given id to tbody element itself.

              So I would suggest you to reconsider your problem domain, think of how you will manage you objects then go for coding. I am saying this because there might be even better way of doing this thing. Projects that fail are 90% due to mismanagement, and 10% due to other reasons.

              Comment

              Working...