Hi All
I have a Javascript problem in a search application.
On my page I've three checkbox-groups with several cb in each.
cb All
cb 1
cb 2
cb 3
cb 4
cb 5
And to set if the cb should be checked or not, I've two scrpits, one
to check or uncheck cb 1 - 5 if "All" is checked or not, and one to
uncheck "All" if one of cb 1-5 is unchecked. But I can´t get the scripts
to uncheck the cb. It seems as the "oCheckBox.checked = true; " doesn't
work. I've tried with "oCheckBox.clicked()" and it changes the state of
the cb, but then i get an onClick event and ends up with one script called
after the first one is done. In script two the "oAllBox.clicked()" will
then call script one, and the state of the cb would be changed.
The code as follow:
For each cb the setOnClientClick lokks like this.
checkBox.setOnClientClick("javascript:" + strCheckAllJavaScriptName + "();");
checkBox.setOnClientClick("javascript:" + strCheckOtherJavaScriptName + "('"+ strCheckBoxId + "');");
The JavaScripts
StringBuffer buffer = new StringBuffer("");
buffer.append("");
HTMLFragment htmlJavaScript = new HTMLFragment(buffer.toString());
layoutCell.addComponent(htmlJavaScript);
StringBuffer buffer2 = new StringBuffer("");
buffer2.append("");
HTMLFragment htmlJavaScript2 = new HTMLFragment(buffer2.toString());
layoutCell.addComponent(htmlJavaScript2);
And in the browsercode i looks like this:
var oAllBox = document.getElementById('htmlb_269_0_1');
if (oAllBox.checked == true) {
var oCheckBox = document.getElementById('htmlb_269_0_2');
if (oCheckBox.checked == false) {
oCheckBox.checked = true;
}
var oCheckBox = document.getElementById('htmlb_269_0_3');
if (oCheckBox.checked == false) {
oCheckBox.checked = true;
}
var oCheckBox = document.getElementById('htmlb_269_0_4');
if (oCheckBox.checked == false) {
oCheckBox.checked = true;
}
var oCheckBox = document.getElementById('htmlb_269_0_5');
if (oCheckBox.checked == false) {
oCheckBox.checked = true;
}
var oCheckBox = document.getElementById('htmlb_269_0_6');
if (oCheckBox.checked == false) {
oCheckBox.checked = true;
}
} else {
var oCheckBox = document.getElementById('htmlb_269_0_2');
if (oCheckBox.checked == true) {
oCheckBox.checked = false;
}
var oCheckBox = document.getElementById('htmlb_269_0_3');
if (oCheckBox.checked == true) {
oCheckBox.checked = false;
}
var oCheckBox = document.getElementById('htmlb_269_0_4');
if (oCheckBox.checked == true) {
oCheckBox.checked = false;
}
var oCheckBox = document.getElementById('htmlb_269_0_5');
if (oCheckBox.checked == true) {
oCheckBox.checked = false;
}
var oCheckBox = document.getElementById('htmlb_269_0_6');
if (oCheckBox.checked == true) {
oCheckBox.checked = false;
}
}
}
var cbID = strCheckBoxId;
var oCheckBox = document.getElementById(cbID);
if (oCheckBox.checked == false) {
var oAllBox = document.getElementById('htmlb_269_0_1');
if (oAllBox.checked == true) {
oAllBox.checked = false;
}
}
}
Any ideas or suggestion would be appreciated
Best regards
Mikael Lofberg