dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: Creating a Form with Javascript

  1. #1
    Join Date
    Dec 2011
    Posts
    7

    Creating a Form with Javascript

    I want to create a checkbox on a form that, when checked, will display a text field for someone to enter text into. If the box isn't checked, though, the text field should not be displayed.

    How do I do this?

    Oh also, it will probably use document.getElementByID(), because that is what we're learning about

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Homework?

    HTML Code:
    <form>
    	<input type="checkbox" onclick="document.getElementById('show_me').style.display = this.checked ? '' : 'none';" />
    	<input id="show_me" type="text" style="display: none;" />
    </form>
    Last edited by bionoid; 12-12-2011 at 06:09 PM. Reason: Added <form> tags even though they're uneless :P

  3. #3
    Join Date
    Dec 2011
    Posts
    7
    Tyvm

  4. #4
    Join Date
    Dec 2011
    Posts
    7
    And yes, homework.

  5. #5
    Join Date
    Dec 2011
    Posts
    7
    Hrm.... How would I apply this to multiple text boxes + tags?

    I thought I could put them all under an article with the ID show_me, but that didn't really work.

  6. #6
    Join Date
    Nov 2010
    Posts
    1,102
    simplest with what you've got now would be just to duplicate the code, swapping "show_me" for some other id (and doing this in the onclick, too)

    probably better would be storing the checkboxes in an array and looping through them, but I suspect that if you submitted that your teacher may get a little suspicious.

  7. #7
    Join Date
    Dec 2011
    Posts
    7
    Wouldn't that mean multiple checkboxes?

    And yeah, we haven't learned about arrays yet, so I don't think he's expecting that.

  8. #8
    Join Date
    Dec 2011
    Posts
    7
    Oh it works with the id in the article, the style= attribute thing was messing it up apparently.

    Now I just need to have it not show right at the start, rather than when I uncheck the box... hmm....

  9. #9
    Join Date
    Dec 2011
    Posts
    7
    omg im stupid, fixed it now though

    DONE! woo

    THANKS FOR THE HELP BIONOID!!!!

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