www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Check box check or uncheck do something

  1. #1
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440

    resolved [RESOLVED] Check box check or uncheck do something

    I have a form where if I check a particular check box it sets an input form to some value, today's date. I have tried unsuccessfully to have it clear the field if I uncheck the checkbox. My javascript skills are limited

    Code:
    function outdate()
    {
    if (document.getElementById("outc").value == "on"){
    document.getElementById("dp").value = "<?php echo $today; ?>"; }
    else{ document.getElementById("dp").value = ""; }
    }
    <body>
    PHP Code:
    <?php
    if ($out == 1) {$ck1 "checked";}else{$ck1 ="";}
    echo 
    "<INPUT type= 'checkbox' ".$ck1." id='outc' onclick='outdate()' name = 'out'>";
    echo 
    "<input type='text'  size='9' name='date_paid' id ='dp' value ='".$a_row['Odate']."'>";
    ?>
    </body>
    Last edited by Dasher; 01-24-2010 at 12:41 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Just to clarify the script sets the field fine. It just won't clear it. Evidently I am not properly getting the checked / not checked status.

  3. #3
    Join Date
    Jan 2010
    Posts
    80
    Hi bud

    You are trying to check the value of the checkbox but you haven’t set it to anything which means that it will never evaluate to true

    You need to check the “checked” parameter of the checkbox which will evaluate to either true or false depending on whether you set it or not

    Code:
         function outdate(){
             if(!document.getElementById("outc").checked){
               document.getElementById("dp").value = ""
                                                        }
             else{
               document.getElementById("dp").value = "22/01/10"
                 }
                            }
    V

  4. #4
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Vince616 Thanks for the reply, but that does not seem to work either.

    Missing something somewhere.

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,440

    Question

    Quote Originally Posted by Dasher View Post
    Vince616 Thanks for the reply, but that does not seem to work either.

    Missing something somewhere.
    What's wrong with it? What error are you getting?

  6. #6
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    OKb- It works. The problem was in another Javascript function. Fixed that and then this one worked fine.

    Thanks guys.... Firebug does help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles