My alert box displays the number of times the user clicks on it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • syedshaffee
    New Member
    • Jan 2012
    • 91

    My alert box displays the number of times the user clicks on it

    hey,
    the code i written is displays me the number of time i click on it here is the code
    Code:
    $(document).ready(function () {    
        //assigning alternative row style
    $("#Table_Data tr:even").addClass("evenrow");
    $("#Table_Data tr:odd").addClass("oddrow"); 
     $("#Table_Data tr:even").click(function(){
       $(this).find(':checkbox').attr('checked', ! $(this).find(':checkbox').attr('checked'));    
       if($(this).find(':checkbox').attr('checked'))
            {
                var html = '';
    $('#Table_Data td').bind("click",function(event) {
        html = $(this).text();
        alert(html);
        $(this).unbind(event)
    });
    
            }
            else
            {
                $(this).removeClass('highlight');
                  $(this).addClass('evenrow');
            }
    });
    $("#Table_Data tr:odd").click(function(){
        $(this).find(':checkbox').attr('checked', !$(this).find(':checkbox').attr('checked'));   
        if($(this).find(':checkbox').attr('checked'))
            {
            $('#Table_Data td').click(function() {
        html = $(this).text();
        alert(html);
    });
            
                 /** $(this).removeClass('oddrow');
                  $(this).addClass('highlight');*/
            }
            else
            {
                $(this).removeClass('highlight');
                  $(this).addClass('oddrow');
            }
    });
    });
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    and what is the problem with that?

    Comment

    • syedshaffee
      New Member
      • Jan 2012
      • 91

      #3
      sorry the problem is that it displays me the data the number of times its clicked eg if i click on it once it displays once and if i click on it the second time it displays me the tiwce

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        and what is it supposed to display?

        Comment

        • syedshaffee
          New Member
          • Jan 2012
          • 91

          #5
          it should display Only once when the user clicks on the tabledata of a table row

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            then you need to remove the event listener in the first click action.

            Comment

            • syedshaffee
              New Member
              • Jan 2012
              • 91

              #7
              If possible can u please provide me the JQuery of it i m using IE 6 and a platform of .net2.0 for asp

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                I do not hand out code. I only help in the process.

                Comment

                • syedshaffee
                  New Member
                  • Jan 2012
                  • 91

                  #9
                  OK removed the event handler and its working fine now the problem is that that the checkbox is already checked here is the code

                  Code:
                  $("#Table_Data tr").find(':checkbox').attr('checked', ! $(this).find(':checkbox').attr('checked'));    
                     if($(this).find(':checkbox').attr('checked'))
                          {
                                var html = '';
                  $(' #Table_Data td').click(function() {
                      html = $(this).text();
                      alert(html);
                  });
                  
                          }
                          else
                          {
                              $(this).removeClass('highlight');
                                $(this).addClass('evenrow');
                          }
                  });
                  i want that the check box should be unchecked when loaded can u pls suggest me what to do? and thanx for the suggestion before

                  Comment

                  Working...