Results 1 to 2 of 2

Thread: javascript checkbox validation

  1. #1
    Join Date
    Sep 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript checkbox validation

    hi.... i used this following code to validate form. in the form there are 4 radio buttons with same name and for each radio there are two or three checkboxes. by default checkboxes are disabled. if user clicks on a radio then checkboxes related to that are enabled, if user clicks different radio then previous redio's checkboxes are disabled and new clicked radio's checkboxes are enabled.

    the following code is working fine but i have to call this function for each radio's onchange event. otherwise it doesnt work for single radio - if i call it for one radio and clicked that radio it works first time and enables the checkboxes but when i click second time on it the checkboxes are disabled.

    function enablecheck()
    {

    if (document.test.category[0].checked)
    {
    document.test.sc1.disabled=false;
    document.test.sc2.disabled=false;
    }
    else
    {
    document.test.sc1.checked=false;
    document.test.sc1.disabled=true;
    document.test.sc2.checked=false;
    document.test.sc2.disabled=true;
    }

    if (document.test.category[3].checked)
    {
    document.test.art1.disabled=false;
    document.test.art2.disabled=false;
    }
    else
    {
    document.test.art1.checked=false;
    document.test.art1.disabled=true;
    document.test.art2.checked=false;
    document.test.art2.disabled=true;
    }
    }

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    See http://www.twey.co.uk/?q=forms -- modify the showEl and hideEl functions defined at the top of the setupDependencies() function to simply disable the element.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •