<div id="myDiv">
<input>
<input type="button" value="red">
<input type="button" value="green">
</div>
<script>
window.onload = function () {
var myDiv = document.getElementById('myDiv');
var inputs = myDiv.getElementsByTagName('input');
myDiv.onclick = function (e) {
e = e || window.event;
var target = e.target || e.srcElement;
if (target.parentNode == myDiv && target != inputs[0]) {
inputs[0].value += target.value + ', ';
}
}
}
</script>