Results 1 to 2 of 2

Thread: Help w/ onClick event

  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help w/ onClick event

    I am trying to show the contents of a div using a onclick event for a check box. The div is set to display:none so its hidden and the check box has not been checked. When the check box has been checked the contents of the div should be shown and when it has been unchecked the div should be hidden again below is the code i am working with.

    JAVASCRIPT:
    Code:
    function showMe (id, box) { 
      var i = (box.checked) ? "block" : "none"; 
      document.getElementById(id).style.display = i; 
    }
    XHTML:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
      <head>
        <title>Test</title>
      </head>
      <body>
              <div>
                <td width="30%">Lorem ipsum:</td>
                <td width="70%">
                  <input name="text" type="checkbox" OnClick="showMe('myDiv', this)"></input>
                  <label for="text">&nbsp;Praesent ut dolor sed risus tincidunt placerat.</label>
                  <div id="myDiv" style="display:none;">
                    <textarea name="test" class="textarea" cols="180" rows="10"></textarea>
                  </div>
                </td>
              </div>
      </body>
    </html>

  2. #2
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OnClick works only with text/html not application/xhtml+xml. For application/xhtml+xml use onclick.

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
  •