Skip to Content
author's profile photo Former Member
Former Member

Javascript/checkbox problem

Also posted in Scripting, General - without any reply.

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Oct 17, 2006 at 04:00 PM

    > Also posted in Scripting, General - without any reply.

    Actually I did reply, please take a look in the other thread. If my answer didn't solve your problem please let me know and I'll extend it.

    :Frederic:

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.