cancel
Showing results for 
Search instead for 
Did you mean: 

HTMLB and Javascript: Dependent Checkboxes

Former Member
0 Kudos

Hello Collegues,

i try to programming a search component with some dependent checkboxes. For example the user should check "checkbox 1" and there should be "checkbox 2" also selected.

I write this small example for this. But it dont works. I thing i have an mistake in the onClientClick function. Does somebody knows the right way to do this?

public class SearchLocalization extends AbstractPortalComponent
{
    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
    {
		//response.write("Javascript Checkbox Test<br>");	
		IPageContext myContext = PageContextFactory.createPageContext(request, response);
		if (myContext == null) {
			response.write("myContext == null");
		}
		Form myForm = myContext.createFormDocument("Javascript Checkbox Test");	
		GridLayout gl = new GridLayout();		
		Checkbox one = new Checkbox("one");
		one.setText("One");		
		gl.addComponent(1,1,one);
		Checkbox two = new Checkbox("two");
		two.setText("two");	
		gl.addComponent(1,2,two);
		myForm.addComponent(gl);
		two.setOnClientClick("javascript:one.checked = true;");		
		myContext.render();				
    }
}

Best regards,

Patrick

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Patrick,

Create a JSPDynPage and in the jsp, u can code javascript like this. I just checked and it is working for me.

<%@taglib uri="tagLib" prefix="hbj"%>

<hbj:content id="myContext" >

<hbj:page title="PageTitle">

<script language="javascript">

function checkme(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var check1 = eval(func("Check1"));

var check2 = eval(func("Check2"));

var check1status = check1.getChecked();

if(check1status==true){

check2.setChecked(true);

}

}

</script>

<hbj:form id="myFormId" >

<hbj:checkbox

id="Check1"

text="Check1"

tooltip="Check1"

disabled="false"

checked="false"

jsObjectNeeded="true"

onClientClick="javascript:checkme();"

/>

<hbj:checkbox

id="Check2"

text="Check2"

tooltip="Check2"

disabled="false"

jsObjectNeeded="true"

checked="false"

/>

</hbj:form>

</hbj:page>

</hbj:content>

Regards,

Harini S

Former Member
0 Kudos

Hi Harini,

thnak you very much for your Help!

But i think i can not use an JSP. I start with the SDN Example "SimpleSearchComponent". There is a method named "renderComponent()". There i can write htmlb controls like in an AbstractPortalComponent.

Best regards,

Patrick

Former Member
0 Kudos

Hi Patrick,

Try replacing the error line as

two.setOnClientClick("javascript: " +

"var funcName = htmlb_formid+\"_getHtmlbElementId\";" +

" func = window[funcName];" +

" var one = eval(func(\"one\"));" +

" var two = eval(func(\"two\"));" +

" var twostatus = two.getChecked();" +

" if(twostatus==true){" +

"one.setChecked(true); }");

This works for me in a dynpage.

Hope that will help in Abstract Portal Component also.

Regards,

Harini S

Former Member
0 Kudos

Hi Harini,

again, thank you very much.

I try to use your function, but it does not work. I get an "no Object Found" Javascript error. When i take a look in the Javasript Debugger i see that there was this coding in my Page:

function htmlb_8819_0_2_onclick(htmlbevent)
{htmlb_formid = 'htmlb_8819_0';
  javascript: var funcName = htmlb_formid+"_getHtmlbElementId"; 
  func = window[funcName]; 
  var htmlb_8819_0_1 = eval(func("one")); 
  var htmlb_8819_0_2 = eval(func("two")); 
  var twostatus = htmlb_8819_0_2.getChecked(); 
  if(twostatus==true){htmlb_8819_0_1.setChecked(true); };
}

Do you have any Idea what i must change?

Best regards,

Patrick

Former Member
0 Kudos

Hi Harini,

yeah, it's working :-).

two.setOnClientClick("javascript:one.setChecked(true);");

was the codeline i was searching for. Thank you very much for your Help!!

Best regards,

Patrick

Former Member
0 Kudos

Hi Patrick,

I forgot to tell u another line to be added.

Add this line.

one.setJsObjectNeeded(true);

two.setJsObjectNeeded(true);

when u r creating the check boxes.

Hope that will solve ur problem.

Regards,

Harini S

-


Happy that it worked. Thanks for the points.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

i be a liddle more specific. My mistake must be in the line:

two.setOnClientClick("javascript:one.checked = true;");

Does anybody knows what i must do there to check an other checkbox per Javascript?

Best regards,

Patrick