How can I change the script below to work as I need it to make the following limit the number of markings or be able to select in the max 2 list items if it exceeds the maximum allowed value of an alert message. >
<html>
<head>
<title>Seleção de Itens</title>
<script type="text/javascript">
//Array que guarda a ordem em que os elementos foram inseridos
var listCheckedOptions = [];
function addToList(checkObj, outputObjID)
{
//Remove do array caso o elemento já esteja inserido
if (listCheckedOptions.indexOf(checkObj.value) >= 0) {
listCheckedOptions.splice(listCheckedOptions.indexOf(checkObj.value), 1);
} else { //Adiciona casojá esteja inserido
listCheckedOptions.push(checkObj.value);
}
// alert(listCheckedOptions); //debug para verificar os elementos inseridos
document.getElementById(outputObjID).value = ""; //Limpa o textarea
document.getElementById(outputObjID).value = listCheckedOptions.join('\r\n'); //Adiciona no textarea
return;
}
</script>
</head>
<body>
<form name="myform">
<input type="checkbox" name="fruit[]" value="Oranges" onClick="addToList(this, 'txt1')"><font color="#808080">Oranges</font><br>
<input type="checkbox" name="fruit[]" value="Apples" onClick="addToList(this, 'txt1')"><font color="#808080">Apples</font><br>
<input type="checkbox" name="fruit[]" value="Grapes" onClick="addToList(this, 'txt1')"><font color="#808080">Grapes</font><br>
<textarea rows="4" cols="10" name="txt1" id="txt1" style="color:#808080" readonly></textarea>
</form>
</body>
</html>