Results 1 to 8 of 8

Thread: if CheckBox.Checked=true then TextBox should be visible

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2004
    Location
    Sydney
    Posts
    51

    if CheckBox.Checked=true then TextBox should be visible

    I have a list of checkboxes(Answers for a Question).
    Each Checkbox has a TextBox which is invisible onFormLoad.

    What I need todo:
    When a user clicks on any of the Checkbox the appropriate Textbox will be Visible.

    How do I do this using client side java scripting?

    Please help me!

  2. #2
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: if CheckBox.Checked=true then TextBox should be visible

    if(!Document.GetElementById('myCheckbox').Checked)
    document.form1.myTextbox.disabled=false;

    The syntax might not be 100% but this should get you started.

    Parksie

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: if CheckBox.Checked=true then TextBox should be visible

    If they are server side controls, you can generate the javascript from your codebehind and send them to the client output using Page.RegisterClientScriptBlock.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2004
    Location
    Sydney
    Posts
    51

    Re: if CheckBox.Checked=true then TextBox should be visible

    if(!document.getElementById('CheckBox1').Checked)
    document.Form1.TextBox1.disabled=false;

    The TextBox1 is enabled when the user checks the CheckBox.

    sure does work, Is there another javascript method to "SHOW/HIDE" the text box?


    Thanks for your help.

  5. #5
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: if CheckBox.Checked=true then TextBox should be visible

    Javascript isn't my thing but I don't think you can do this without DHTML though don't quote me on it.

    Sorry

    Parksie

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: if CheckBox.Checked=true then TextBox should be visible

    Set the .style.visibility property to either "visible" or "hidden".

  7. #7
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Re: if CheckBox.Checked=true then TextBox should be visible

    mendhak, what property could you set for a DropDownList control to make it hidden?

    Thanks
    David Wilhelm

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: if CheckBox.Checked=true then TextBox should be visible

    The DropDownList, on the client side (which is where you want to do this from), is nothing but a <select> box. So all you need is its ID.

    Let's say you have a javascript method, XYZ(), that can turn any element invisible (as shown earlier).

    From your codebehind, when you are creating the call, pass it the .ClientID property of the server side control.

    Code:
    strJS += "XYZ('" + myDDLBox1.ClientID + "');";

Posting Permissions

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



Click Here to Expand Forum to Full Width