I am facing a js error in my code, below is the prob. statement
I have a radio2 javascript function as below, it works like this..
When a parent radio button is selected only one of its child radio button can be selected and on selection of a new child button(of the same parent) the earlier child button is deselected.
When i navigate to this particular page and select a parent and select a child, when i select another child of the same parent the radio is selected( this should not have been the behaviour) and the below error is displayed:
form.elements[...].checked is null or not an object.
The js pop-up says the below line is the error(line marked in bold in source code):
thisObj.form.elements[parentRadioButtonName].checked=true;
My javascript code:
------------------
Expand|Select|Wrap|Line Numbers
- function sL_radio2_onclick(thisObj, thisEvent) {
- //use 'thisObj' to refer directly to this component instead of keyword 'this'
- //use 'thisEvent' to refer to the event generated instead of keyword 'event'
- // find the parent array number
- var indexStart = eval("form1:table1:".length);
- var indexEnd = thisObj.name.indexOf(':table2');
- var parentIndex = thisObj.name.substring(indexStart,indexEnd);
- // check the parent if child is checked and parent is not checked before
- parentRadioButtonName = 'form1:table1:'+parentIndex+':radio1';
- if (thisObj.checked && (!thisObj.form.elements[parentRadioButtonName].checked)) {
- thisObj.form.elements[parentRadioButtonName].checked=true;
- //uncheck other parent
- for(i=0;1==1;i++){
- parentRadioButtonName = 'form1:table1:'+i+':radio1';
- if (thisObj.form.elements[parentRadioButtonName]) {
- //if this parent is checked and not the parent of current child
- if(thisObj.form.elements[parentRadioButtonName].checked && (i != parentIndex)){
- thisObj.form.elements[parentRadioButtonName].checked=false;
- //uncheck children of this parent
- for(j=0;1==1;j++){
- childRadioButtonName = 'form1:table1:'+i+':table2:'+j+':radio2';
- if(thisObj.form.elements[childRadioButtonName]){
- thisObj.form.elements[childRadioButtonName].checked=false;
- } else {
- break;
- }
- }
- }
- } else {
- if (i>parentIndex) {
- break;
- }
- }
- }
- }
- //if this child is checked, uncheck other children
- // which has same parent as this child
- if (thisObj.checked) {
- for(i=0;1==1;i++){
- childRadioButtonName = 'form1:table1:'+parentIndex+':table2:'+i+':radio2';
- if(thisObj.form.elements[childRadioButtonName]){
- //check this child is not itself
- if (!(thisObj.form.elements[childRadioButtonName]==thisObj)) {
- thisObj.form.elements[childRadioButtonName].checked=false;
- }
- } else {
- break;
- }
- }
- }
- }
-------
Expand|Select|Wrap|Line Numbers
- <h:selectOneRadio styleClass="selectOneRadio" id="radio2"
- value="#{pc_SL.objectSpace.sPd}"
- onclick="return sL_radio2_onclick(this, event);">
- <f:selectItem
- itemValue="#{varBObj.OrgBObj.sSId}"
- itemLabel=" " />
- </h:selectOneRadio>