on 05-15-2006 4:13 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.