SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Need help for chekboes

    Hello, I need some help regarding on the checkboxes, How do i get the emp_actno if the checkbox is selected,
    for example this data: 01,02,04 are selected and i want to get this 101,102 and 104.
    HTML Code:
      <tr>
       <input type="checkbox" value="01" name="emp">
       <td>john</td>
       <td>manager</td>
       <td>101</td>
      </tr>  
    
     <tr>
       <input type="checkbox" value="02" name="emp">
       <td>mathias</td>
       <td>SEO</td>
       <td>102</td>
      </tr>  
    
     <tr>
       <input type="checkbox" value="03" name="emp">
       <td>jack</td>
       <td>supervisor</td>
       <td>103</td>
      </tr>  
    
     <tr>
       <input type="checkbox" value="04" name="emp">
       <td>Gibson</td>
       <td>Team leader</td>
       <td>104</td>
      </tr>  
    


    Thank you in advance

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    First of all, why don't you put the value you want to get in the value of the checkbox?
    Second, if you have to send the form data to a PHP script, then give the checkboxes the name emp[] . I don't know if it makes a difference for javascript, but in PHP you will be able to access the checked box values in the $_POST['emp'] array.

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi guido2004,Thank you for the reply.
    First of all, why don't you put the value you want to get in the value of the checkbox?
    I have other function that used to get the value of the checkbox
    Second, if you have to send the form data to a PHP script, then give the checkboxes the name emp[]
    can you please show me example of this,i have no idea for this and i never yet tried to use name in array.

    Thank you in advance.

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Okay i got it now.thank you.

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi jemz,

    You can do it like this:

    HTML Code:
    <!DOCTYPE HTML>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>nextAll()</title>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
      </head>
      <body>
        <table>
          <tr>
            <td><input type="checkbox" value="01" name="emp" checked></td>
            <td>john</td>
            <td>manager</td>
            <td>101</td>
          </tr>  
          
          <tr>
            <td><input type="checkbox" value="02" name="emp" checked></td>
            <td>mathias</td>
            <td>SEO</td>
            <td>102</td>
          </tr>  
          
          <tr>
            <td><input type="checkbox" value="03" name="emp"></td>
            <td>jack</td>
            <td>supervisor</td>
            <td>103</td>
          </tr>  
          
          <tr>
            <td><input type="checkbox" value="04" name="emp" checked></td>
            <td>Gibson</td>
            <td>Team leader</td>
            <td>104</td>
          </tr> 
        </table> 
         
        <script>
          $('input:checked').each(function() {
            console.log($(this).parent().nextAll().eq(2).text());
          });
        </script>
      </body>
    </html>

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi pullo ,is this will get the value of td if the checkbox is checked?

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    No, but this will:

    Code JavaScript:
    $('input[type="checkbox"]').change(function(){
      $('input:checked').each(function() {
        console.log($(this).parent().nextAll().eq(2).text());
      });
    });

    At least I hope this is what you mean.

  8. #8
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    No, but this will:

    Code JavaScript:
    $('input[type="checkbox"]').change(function(){
      $('input:checked').each(function() {
        console.log($(this).parent().nextAll().eq(2).text());
      });
    });

    At least I hope this is what you mean.
    Hi pullo, it's working thank you so much.

  9. #9
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    No problem jemz,
    Thanks for taking the time to report back


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •