Well folks would like to know who can help me. I found this script in this American forum link script, it literally does appear the values marked inside the textarea, yet it adds the items following the order of the checkboxes list.
<html>
<head>
<title>Fruits</title>
<script type="text/javascript">
function addToList(checkObj, outputObjID)
{
var checkGroup = checkObj.form[checkObj.name];
var checkGroupLen = checkGroup.length;
var valueList = new Array();
for (var i=0; i<checkGroupLen; i++)
{
if (checkGroup[i].checked)
{
valueList[valueList.length] = checkGroup[i].value;
}
}
document.getElementById(outputObjID).value = valueList.join('\r\n');
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>
Now here's my question, I would like to know how I can change it so that it places the values in the textarea by adding the items in the order in which I activate a checkbox, that is, say I have items 1,2 and 3 ; if I add the way the script is currently in that order 2,1,3 the order placed inside the textarea will be 1,2,3 I would like following the example to be in the order I marked, ie 2,1,3 . It is possible? If so, could anyone help me? I'm still a beginner and it would help me a lot.
Well, it worked, but if it does not bother you, just find it with a full complement of buttons. How would you help me by putting in the code that you already pass and thank you for putting the full function on it? As it is in the code below that I posted more complement.
<script type="text/javascript">
function addToList(checkObj, outputObjID)
{
var checkGroup = checkObj.form[checkObj.name];
var checkGroupLen = checkGroup.length;
var valueList = new Array();
for (var i=0; i<checkGroupLen; i++)
{
if (checkGroup[i].checked)
{
valueList[valueList.length] = checkGroup[i].value;
}
}
document.getElementById(outputObjID).value = valueList.join('\r\n');
return;
}
function checkAllBox(formObj, fieldName, checkedState)
{
if(formObj[fieldName].length)
{
var fieldLen = formObj[fieldName].length;
for(var i=0; i<fieldLen; i++)
{
formObj[fieldName][i].checked = checkedState;
addToList(formObj[fieldName][i], 'txt1');
}
}
else
{
formObj[fieldName].checked = checkedState;
addToList(formObj[fieldName], 'txt1');
}
return;
}
<form name="myform">
<input type="checkbox" name="checkAll" value="all" onClick="checkAllBox(this.form, 'fruit[]', this.checked);" /><b>Check All</b><br>
<input type="checkbox" name="fruit[]" value="Oranges" onClick="addToList(this, 'txt1');" /><span style="color:#808080">Oranges</span><br>
<input type="checkbox" name="fruit[]" value="Apples" onClick="addToList(this, 'txt1');" /><span style="color:#808080">Apples</span><br>
<input type="checkbox" name="fruit[]" value="Grapes" onClick="addToList(this, 'txt1');" /><span style="color:#808080">Grapes</span><br>
<textarea rows="4" cols="10" name="txt1" id="txt1" style="color:#808080" readonly="readonly"></textarea>