Hi Guys,
I need help on this section. I'm trying to get this piece of Javascript to work with my system:
<SCRIPT language="JavaScript">
function CheckAll()
{
count = document.formArticleEdit.elements.length;
for (i=0; i < count; i++)
{
if(document.formArticleEdit.elements.checked == 1)
{document.formArticleEdit.elements.checked = 0; }
else {document.formArticleEdit.elements.checked = 1;}
}
}
function UncheckAll(){
count = document.formArticleEdit.elements.length;
for (i=0; i < count; i++)
{
if(document.formArticleEdit.elements.checked == 1)
{document.formArticleEdit.elements.checked = 0; }
else {document.formArticleEdit.elements.checked = 1;}
}
}
function CheckSelection(currentState)
{
if (document.formArticleEdit.articleStatus.options[document.formArticleEdit.articleStatus.selectedIndex].value != "currentState")
document.formArticleEdit.toggleSelect.checked = 1;
else if (document.formArticleEdit.articleStatus.options[document.formArticleEdit.articleStatus.selectedIndex].value == "currentState")
document.formArticleEdit.toggleSelect.checked = 0;
}
</SCRIPT>
*******************************************************
The codes should communicate in looped sections of my code as provided below:
*******************************************************
print (" <TD bgcolor=\"#FCEDB5\" class=\"padded\" align=\"center\"><INPUT type=\"checkbox\" name=\"toggleSelect\" value=\"$articleID\"></TD>\n");
print (" <TD bgcolor=\"#FCEDB5\" class=\"padded\" align=\"center\"><SELECT name=\"articleStatus\" id=\"articleStatus\" onChange=\"CheckSelection('$articleVisibility')\">\n");
*******************************************************
What the code does is that when the value of articleStatus changes from what was reported from an SQL listing, a checkbox would be checked. If the original value is selected, the checkbox is unchecked. The check box is supposed to be some sort of flag indicating that a change was made to the record.
Here's the thing: the codes that I wrote works on one record. When multiple records are reported (i.e. records drawn from MySQL), the codes won't work. Plus, it won't revert to its unchecked state when articleStatus is changed back to its original value.
I need my codes to do some things:
Work within a Check All/Uncheck All framework,
Change the status of a checkbox when articleStatus is changed, and
Make the codes work when PHP calls for a nested loop to display mutiple records.
Any ideas? Many thanks in advance. 🙂