SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ankitaneja1's Avatar
    Join Date
    Sep 2004
    Location
    India
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!
    Ankit Aneja
    "Nothing is impossible. The word itself says - I M possible"

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •