PDA

View Full Version : Help w/ onClick event



integer
02-19-2010, 04:26 AM
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:


function showMe (id, box) {
var i = (box.checked) ? "block" : "none";
document.getElementById(id).style.display = i;
}

XHTML:


<?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>

integer
02-19-2010, 04:36 AM
OnClick works only with text/html not application/xhtml+xml. For application/xhtml+xml use onclick.