views:

72

answers:

2

1 naga naga123

2 Tamil tamil123

3 vinod vinod123

4 naveen naveen123

5 jakkir jakkir123

save    edit    delete

 UserID:

 UserName:

 Password: 

I have check box at the end of each row. When I click the check box and select edit the values should get displayed in the text boxes corresponding to userId, userName & Password.

My js code for edit is

     function Edit(){
     var i=dwr.util.getValue("userId");
     LoginManagement.selectId(i,function(login){
     dwr.util.setValues({userId:userId, userName:login.userName,
     passWord:login.passWord});     
     });
     }

My js code for checkbox is

         function Intialize(){
        LoginManagement.getLoginDetails(function(loginList){
         var x = "";
         for(var i=0; i<loginList.length; i++){
          var login =loginList[i];
          x += "<tr><td>"+login.userId+"</td><td>"+login.userName+"</td><td>"+login.passWord+"</td><td><input type = 'checkbox' id = 'cbid"+login.userId+"'</td></tr>";
        }
        $("#loginTable").html(x);

            });
                }

How should i get the id value in edit so that if i click the button it should display the values corresponding. Any suggestion please?

+1  A: 

the id can be retrieved by using the attr var idvalue = $("input:last").attr("id"); but you have to get reference to the checkbox in your scenario .. if you have a css class name associated with it use that like $(.classname) and then use the attr to get the value.

Suhumar
+1  A: 

Hope I understand you correctly.

Remove Edit() from onclick of edit link and continue the Initialize function as follows:

...

      $("#loginTable").html(x);

      ids = ['userId', 'userName', 'Password']; // Ids of text boxes to be populated

      $("#editlink").click(function(){ // Assuming edit link has id="editlink"
        var tds = $("#loginTable").find("input:checked[type=checkbox]").parent().siblings();
        for(var i = 0; i < ids.length; i++){
          $('#' + ids[i]).html($(tds[i]).html());
        }
        Edit(); // Better copy the code of Edit() directly in here
        return false; // Prevent default click action (go to href)
      });

    });

If this is wrong please post the complete HTML as well.

sunn0
@sunnO the function should fire if i click the edit button. i got the id values using var id=$('input[type=checkbox]:checked').attr('id');var userId = id.substring(4);
Code 'N' Weed
it sets the value but it reloads automatically now. i am woking on that now
Code 'N' Weed
If you don't remove Edit() from the onclick attribute it will fire twice. Updated to prevent reload and saw that Edit was outside of the click event handler so you can really remove it from onclick now.
sunn0