Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    6
    Thanked 0 Times in 0 Posts

    keep checkbox checked

    Hi. I'm having a pretty hard time figuring how to do something... In a nutshell, I have a form, when submitted it calls a php page that emails me the form, if it can't email it, it stores the form field values in a txt file, then calls up another php page, which is actually the form with the fields already populated (the field values are read from the file and assigned to the respective fields). What I'm having trouble with is some checkboxes and radios: they already have values assigned to them, so I don't know how to check them if they were previously checked.
    Anyway...maybe part of the code will clear things up a bit:
    Code:
    <?php
    $fis_txt=fgets($eroare, 102400);
    $text_txt=fgets($eroare, 102400);
    $nav_sel=fgets($eroare, 102400);
    for($i=0; $i<22; $i++)
     {$navs.$i=fgets($eroare, 102400);}
    ?>
    
    <html>
    <input type="radio" name="Text" value="Fisier" onClick="Val_text();Cont_pag2();">Check the one that was previously checked
    <input type="radio" name="Text" value="Text" onClick="Val_text();Cont_pag2();">Check the one that was previously checked
    <input type="file" name="Fis_txt" size="100" value="<?php echo $fis_txt; ?>" onChange="Cont_pag2()">
    <textarea name="Text_txt" cols="80" rows="10" value="<?php echo $text_txt; ?>" onKeyUp="Cont_pag2()">
    
    <input type="checkbox" id="Navs0" name="Navs0" value="1" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
    <input type="checkbox" id="Navs1" name="Navs1" value="1" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
    <input type="checkbox" id="Navs2" name="Navs2" value="2" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
    And so on until Navs21
    </html>
    Well...like I said, this is just a small part of the code...the entire file has about 80KB...
    Anyway...If the checkbox was previously checked, in the txt file the respective line would say ON, if it was unchecked it would say OFF. And for the radios, the txt file would contain the value of the one that was checked.

    So...How do I go and do that? Any help will be very much appreciated...

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    What I'm having trouble with is some checkboxes and radios: they already have values assigned to them, so I don't know how to check them if they were previously checked.
    How do you know whether a check box was checked or not? Any clue left in the variable $navs.$i ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    How do you know whether a check box was checked or not? Any clue left in the variable $navs.$i ?
    I already said...if the checkbox was checked, the respective line would contain the word "ON", so $navs.$i would have the value "ON". If it wasn't checked, the line (and ultimately $navs.$i) would contain the word "OFF".

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Try
    PHP Code:
    <?php
    for($i=0$i<22$i++)
     {
     
    $navs.$i=fgets($eroare102400);
     
    $checked=($navs.$i=='On')?'checked="checked"':'';
     
     echo 
    "<input type=\"checkbox\" {$checked} id=\"Navs{$i}\" name=\"Navs{$i}\" value=\"{$i}\" onClick=\"Cont_pag5_3()\">";
     
     }
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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