Results 1 to 3 of 3

Thread: Show/Hide function using checkbox

  1. #1
    Join Date
    May 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Show/Hide function using checkbox

    Hi Guys

    Could someone give me a hand?

    I've got an asp form which will allow users to update their profile. At the bottom of the form there is a checkbox which depending on it's status will display some additional information for the user to fill out.

    The checkbox's initial value will be generated from their user record from the database. From here I then want to be able to hide/show the additional fields depending on both the checkbox checked status and the db variable. This would give 6 different combinations:

    db variable = 1, checkbox = NULL, additional fields = show
    db variable = 0, checkbox = NULL, additional fields = hide
    db variable = 1, checkbox = 1, additional fields = show
    db variable = 0, checkbox = 0, additional fields = hide
    db variable = 1, checkbox = 0, additional fields = hide
    db variable = 0, checkbox = 1, additional fields = show

    Any ideas on how to write this as a function?

    Thanks in advance
    Leigh

  2. #2
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default

    Maybe like this.

    Code:
    //obj is the HTML object
    //db is a variable you pass
    function additionalInfo(obj, db)
    {
    if( (obj.checked && db) || (obj.checked && !db) || (obj.checked == null && db))
    {return true;}
    else
    {return false;}
    }
    Will return true for show, and false for hide.
    In javascript using '==' means that 1==true and 0==false

    Code:
    <input type="checkbox" onchange="additionalInfo(this,dbvalue)">
    Last edited by Bob90; 05-25-2007 at 05:06 PM.

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm somewhat confused as a checkbox cannot be "null": it's either checked (and successful) or not.

    Is there some reason why this cannot be a two-part form?
    Mike

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
  •