Say I have a set of check boxes:
(checked) Psychology
(checked) Introduction to Mathematical Studies
(unchecked) Introduction to Java Language
(checked) Database Systems
And I click a button 'Next', which passes all these values to the next page by $_GET.
On the next page, I have the exact same set of checkboxes, and I want to use these values to recheck the checkboxes.
I wrote some code here, which works, but problem is it is in javascript and not ideal because if the user has js turned off it wouldnt work.
Code: Select all
for (var subject_count = 0; subject_count < subject.length; subject_count++) {
var inputs = document.getElementsByTagName ('input');
if (inputs) {
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'checkbox' && inputs[i].name == 'my_subject[]') {
if (inputs[i].value == subject[subject_count])
inputs[i].checked = true;
}
}
}
}
Code: Select all
<input type="checkbox" name="my_subject[]" value="801"/> blah...
<input type="checkbox" name="my_subject[]" value="802"/> blah blah..
My question is, how do I specify a checkbox like that in php? Or what can I do alternatively?