Problem in javascript method to check if grid exists and row is selected

Hi All,
I have a left side textbox and a find button and similarly, a right side textbox and a find button. Clicking on the either side button will display a grid with populated data. The right side button should not display any grid, IF the left side grid is not displayed and any row is not selected in that grid. for this validation, I have scripted the code as follows: ( this gets called on right side button onclientclick=“return ParentValidate()” event)

Collapse | Copy Code
<div class=“FQA”>Quote:</div>blockquote class=“FQ”><div class=“FQA”>Quote:</div><script language=“javascript” type=“text/javascript”>
function ParentValidate() {
debugger;
var childflagP = 0;
var gridchildP = null;
var gridchildP = document.getElementById(“<%=GrdLeftSide.ClientID%>”);
if (gridchildP != null) {
var rbchildP = gridchildP.getElementsByTagName(“input”);
for (var i = 0; i < rbchildP.length; i++) {
if (rbchildP[i].type == “radio”) {
if (rbchildP[i].checked) {
childflagP = 1;
break;
}
}
}
}

   if (childflagP == 0) {
       alert("Please Select a row in the left grid");
       return false;
   }
   else {
       return true;
   }

}
</script>

If left grid is present, if even though no row is selected in it, this method works fine. But if, no grid is present on the page, this method doesn’t get called and right grid gets displayed without passing this validation.

Please help how to get the method called even if there is no grid on the screen.

Thanks!

A couple of points:

  1. you’ve been a member since 2004 and made 200+ posts so you should be aware that posted code should be wrapped in appropriate code tags for readability and they would get rid of those pesky gremlins about to munch up your code. You also risk putting people off even trying to help when they see unwrapped code.

  2. It appears you need to do some debugging to fix the logic errors in your code. You can either use a debugger in your browser or step through your code and place alert()'s at appropriate places to check values of variables and to see if parts of your code are reached. When an alert() pops up something it shouldn’t then back track your code from there to locate the source of the problem and fix it.