1
Well people would like to know who can help me. I found this script in this American forum http://forums.phpfreaks.com/topic/170591-solved-checkbox-populating-a-text-area works the script, literally shows the values marked inside the textarea, with everything 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 wonder how I can change this so that it puts the values in the textarea by adding the items in the order in which I activate a checkbox, ie, say I have items 1,2 and 3; if I add the way the script is at the moment 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. Is that possible? If yes, could someone help me? I’m a beginner yet and it would help me a lot.
Valeu worked more like if it is not bothering see I only found it with a complement with a full button would be able to help me with this by putting in the code that you already pass me and I really appreciate putting in it the full function ? As this in the code below old 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>
Put what you’ve managed to develop so far into the question.
– ptkato
When asking questions, try not to leave the title so vague, and make the most of the added tags. For this specific question the tag php is unnecessary since the treated code concerns only HTML and Javascript, ie client-side (browser).
– Adriano Leal
A tip: Try to understand the code before posting. A lot can be solved just by understanding the code. If you don’t have any language skills, it’s a great time to learn. Putting codes here for others to do for you is not the best solution. At some point, people get as boring as the international, and they’re not gonna do their job. Nothing personal, just that this community is to help people with doubts and programming problems and not do the work or think for others. Anything, take a look at FAQ.
– Ricardo Souza