There are four boxes containing values. When clicking on a box, the value should appear in a text field separated by commas if multiple boxes are selected.
<li><a href="javascript:void(0)" onclick="check_stalls('A-14')" id="A-14">A-14</a></li>
<li><a href="javascript:void(0)" onclick="check_stalls('A-13') id="A-13">A-13</a></li>
<li><a href="javascript:void(0)" onclick="check_stalls('A-12') id="A-12">A-12</a></li>
<li><a href="javascript:void(0)" onclick="check_stalls('A-11') id="A-11">A-11</a></li>
<input type="text" name="selected_stals" id="selected_stals" />
function check_stalls(stalno)
{
alert(stalno);
document.getElementById(stalno).style.backgroundColor = "#FF0";
var textbox = document.getElementsByName("selected_stals")[0];
var checkboxes = stalno;
alert(checkboxes);
for (var i = 0; i < checkboxes.length i++) {
var checkbox = checkboxes[i];
checkbox.onclick = (function(chk){
return function() {
var value = "";
for (var j = 0; j < checkboxes.length; j++) {
if (checkboxes[j].checked) {
if (value === "") {
value += checkboxes[j].value;
} else {
value += "," + checkboxes[j].value;
}
}
}
textbox.value = value;
}
})(textbox);
}
}
I attempted to implement this using checkboxes but encountered some issues...