Hey all, I'm trying to give this function some automation instead of hard coding everything.
I have 2 functions
Function 1
Function 2
I'm new to javascript and someone on this forum (I think) helped me with this problem I had, so I don't want to take credit for the code above.
At any rate, what I'm sending to function reconfig, are elements in a form (radio buttons, checkboxes, textboxes, etc...). Here's an illustration below on my current setup:
RadioButton1 Name=Q01 ID=Q01A
TableRoW ID=Q01A_id
Checkbox Name=Q01A01C ID=Q01A_id
TableRow ID=Q01A01C_id
TextBox Name=Q01A01C01 ID=Q01A_id
RadioButton2 Name=Q01 ID=Q01E
At the start, RadioButton2 is selected and all the elements under RadioButton1 are hidden (display='none'). When I select RadioButton1, and select all the elements under it and then re-select RadioButton2, all the elements under RadioButton1 are hidden (which is good). However, when I select RadioButton1 again, the TextBox appears under the checkbox (this shouldn't happen unless the checkbox is checked).
I think the line where I use isdefined to see if the row name is there is the problem. My thought process is, if the rowname is defined, then hide that row, else, don't.
How can I use these functions to hide a table row without hardcoding the tablerow id into the function?
If you need more info, just ask, I'll post the rest of the function if needed, but, I didn't want to clutter it up.
Thanks!
I have 2 functions
Function 1
Code:
function isdefined(variable)
{
return (typeof(window[variable]) == "undefined")? false: true;
}
Function 2
Code:
function reconfig(obj,start,end) {
var sname=obj.name;
var sid=obj.id;
var strid=sid+"_id";
var re=new RegExp("sid");
var oform=obj.form;
for (var i=start; i<end;i++) {
var oelem=oform.elements[i];
.
.
if (oelem.type=="checkbox" && !re.test(oelem.id)) {
oelem.checked=false;
var rowname = oelem.name+"_id";
if (isdefined(document.getElementById(rowname))) {
document.getElementById(rowname).style.display = 'none';
}
}
.
.
}
}
I'm new to javascript and someone on this forum (I think) helped me with this problem I had, so I don't want to take credit for the code above.
At any rate, what I'm sending to function reconfig, are elements in a form (radio buttons, checkboxes, textboxes, etc...). Here's an illustration below on my current setup:
RadioButton1 Name=Q01 ID=Q01A
TableRoW ID=Q01A_id
Checkbox Name=Q01A01C ID=Q01A_id
TableRow ID=Q01A01C_id
TextBox Name=Q01A01C01 ID=Q01A_id
RadioButton2 Name=Q01 ID=Q01E
At the start, RadioButton2 is selected and all the elements under RadioButton1 are hidden (display='none'). When I select RadioButton1, and select all the elements under it and then re-select RadioButton2, all the elements under RadioButton1 are hidden (which is good). However, when I select RadioButton1 again, the TextBox appears under the checkbox (this shouldn't happen unless the checkbox is checked).
I think the line where I use isdefined to see if the row name is there is the problem. My thought process is, if the rowname is defined, then hide that row, else, don't.
How can I use these functions to hide a table row without hardcoding the tablerow id into the function?
If you need more info, just ask, I'll post the rest of the function if needed, but, I didn't want to clutter it up.
Thanks!