SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Need help for chekboes

  1. #1
    SitePoint Guru
    Join Date
    May 2012
    Posts
    635
    Mentioned
    0 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 bronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    8,604
    Mentioned
    76 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 Guru
    Join Date
    May 2012
    Posts
    635
    Mentioned
    0 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 Guru
    Join Date
    May 2012
    Posts
    635
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay i got it now.thank you.

  5. #5
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,441
    Mentioned
    39 Post(s)
    Tagged
    1 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>
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

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

  7. #7
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,441
    Mentioned
    39 Post(s)
    Tagged
    1 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.
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  8. #8
    SitePoint Guru
    Join Date
    May 2012
    Posts
    635
    Mentioned
    0 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
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,441
    Mentioned
    39 Post(s)
    Tagged
    1 Thread(s)
    No problem jemz,
    Thanks for taking the time to report back
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

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
  •