Results 1 to 2 of 2

Thread: Onclick check checkbox then do action

  1. #1
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default Onclick check checkbox then do action

    I have the code:

    PHP Code:
    <?php
    $thefile 
    'shouts.txt';
    $dataf 'shouts.txt';
    $url $_POST['url'];
    $message $_POST['message'];

      function 
    deleteLine($file$lineNum) {
        
    $c file($file);
        
    $c[$lineNum] = '';
        
    $c implode(''$c);
        
    $f fopen($file'w');
        
    fwrite($f$c);
        
    fclose($f);
      }

      if(isset(
    $_POST['Submit']))
        
    $file fopen("$dataf","a");
        
    $write fwrite($file,"<a href=$url>$message</a>  &middot;&middot;  ($url)
    "
    );
        
    fclose($file);


      if(isset(
    $_POST['lines']) && isset($_POST['del']))
        for(
    $i 0$i count($_POST['lines']); ++$i)
          
    deleteLine($thefile$_POST['lines'][$i]);

      
    $c file('shouts.txt');
    ?>
    <form action="<?php echo($PHP_SELF); ?>" method="post">
    <?php for($i 0$i count($c); ++$i) { ?>
      <label style="display: block;">
        <input type="checkbox" name="lines[]" value="<?php echo($i); ?>"><input type="submit" name="del" value="X">
        <?php echo($c[$i]); ?>
      </label>
    <?php ?>
    #1<input name="message" size= "30" type="text" id="message">
    #2<input name="url" size="30" type="text" id="url">
      <input type="submit" name="Submit" value="Submit"><input type="reset" name="Reset" value="Reset">
    </form>

    I need to make it so that when you click on the button named "del" it will do the action of deleting the line... Currently it has to be set that the box has to be checked before it deletes, how do I make it so it doesn't need to be checked, just click the button next to it and it deletes the line?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    you could probably make up the submit button just a button, then do onclick="window.location='?act=deleteline&linenum=<?php echo ($i); ?>';">

    Then in the php file itself, add $act = $_REQUEST["act"]; and make an if statement that goes like so - if ($act == "deleteline") { deleteline($linenum); }
    or something to that effect.
    Hope this kinda helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •