SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    enable/diasble fields with checkbox problem

    Guys,

    I have this code to enable/disable fields in my page.

    PHP Code:
    <script language="javascript">

    function 
    enabledisableFields1()
    {

    if ( 
    document.persoons.reservatienzhuis.checked ) {   

        
    document.persoons.vertrekdatumnzdag.disabled=false;
        
    } else {  
        
    document.persoons.vertrekdatumnzdag.disabled=true;
        
         
    }
     
    </script> 
    In my page , I call this function with

    PHP Code:
    onclick="javascript:enabledisableFields1()" 
    It doesn't do anthing however. Can someone point me to the solution, please ? 'persoons' is the name of the form, 'reservatienzhuis' is the name of the checkbox.

    Many thanks,
    Michel

  2. #2
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try use this code
    javascript to insert within head tags
    <script language="javascript">

    function ENBS(thisval)
    {
    if(thisval.checked)
    {
    document.getElementById('tf').readOnly=true;
    }
    else
    {
    document.getElementById('tf').readOnly=false;
    }
    }
    </script>

    second thing the form which u need to add anywhere u like in body tags
    <form action="" method="post" name="person" id="persoons">
    <input name="tf" type="text" id="tf">
    <input name="type" type="checkbox" id="type" value="checkbox" onClick="ENBS(this);" >
    </form>

  3. #3
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also give this a try.

    -- Enable --
    document.getElementById("vertrekdatumnzdag").disabled = false;

    -- Disable --
    document.getElementById("vertrekdatumnzdag").disabled = true;

    Make sure the vertrekdatumnzdag check box has an id defined as vertrekdatumnzdag. I have a lot better luck using id than name on objects.


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
  •