SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: checkbox update

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checkbox update

    hello
    I have checkbox to display the months .Is good in the insert form But in the update form I want the months that have been checked in the insert form ,have checked in the update form
    i used this code to dispaly check boc

    HTML Code:
     <input type="checkbox" name="months[]" id="months" value="<?php echo $key; ?>" >
    any help?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You need to add some code to see if the box was already checked, if it was add the checked="checked" attribute the input.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know that,but how ? can you help me?

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You need to emulate something similar to:-
    PHP Code:
    <?php
    $checked 
    = array(
      
    'bar'
    );

    $boxes = array(
      
    'foo',
      
    'bar'
    );

    foreach(
    $boxes as $box){
      
    printf(
        
    '<input type="checkbox" %s name="%s" />' PHP_EOL,
        
    in_array($box$checked) ? 'checked="checked"' '',
        
    $box
      
    );
    }

    /*
      <input type="checkbox"  name="foo" />
      <input type="checkbox" checked="checked" name="bar" />
    */
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •