Check box Alert if only One check Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitindel
    New Member
    • Dec 2007
    • 67

    Check box Alert if only One check Box

    Hi All,
    I am working on ASP , VBScript and Javascript.
    I am making a grid in ASP VBScript..and eneter checkboxes in one column......

    The problem is that if there is one record in the grid it is showing as :

    Even If the record is selected ,the alert is like(Please select the record to edit or delete)...

    Below is the javascript code that i am using on Button click

    [Code]:
    function Edit()
    {
    var ctr=0;
    for (i=0;i<document .managecontribu tion.checkmanag e.length;++i )
    {
    if (document.manag econtribution.c heckmanage[i].checked)
    {
    ctr=ctr+1;

    }

    }

    [Code]


    Also i am using the Html "Submit" type not the "button" type


    Thanks in Advance
  • nitindel
    New Member
    • Dec 2007
    • 67

    #2
    Chek box Alert if only One check Box

    Hi All,
    I am working on ASP , VBScript and Javascript.
    I am making a grid in ASP VBScript..and eneter checkboxes in one column......

    The problem is that if there is one record in the grid it is showing as :

    Even If the record is selected ,the alert is like(Please select the record to edit or delete)...

    Below is the javascript code that i am using on Button click

    [Code=javascript]:
    function Edit()
    {
    var ctr=0;
    for (i=0;i<document .managecontribu tion.checkmanag e.length;++i )
    {
    if (document.manag econtribution.c heckmanage[i].checked)
    {
    ctr=ctr+1;

    }

    }

    [/Code]


    Also i am using the Html "Submit" type not the "button" type


    Thanks in Advance
    Last edited by acoder; Feb 21 '08, 11:29 AM. Reason: fixed code tag

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      Originally posted by nitindel
      Hi All,
      I am working on ASP , VBScript and Javascript.
      I am making a grid in ASP VBScript..and eneter checkboxes in one column......

      The problem is that if there is one record in the grid it is showing as :

      Even If the record is selected ,the alert is like(Please select the record to edit or delete)...

      Below is the javascript code that i am using on Button click

      Code:
      :
      function Edit()
      {
      var ctr=0;
      for (i=0;i<document.managecontribution.checkmanage.length;++i )
      {
      if (document.managecontribution.checkmanage[i].checked)
      {
      ctr=ctr+1;
      
      }
      
      }

      Also i am using the Html "Submit" type not the "button" type


      Thanks in Advance

      What are you doing to ctr afterwards?
      is it this....
      Code:
      if (!ctr) alert('Please select the record to edit or delete');

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        You won't get any better answers by repeating the question..

        Comment

        • nitindel
          New Member
          • Dec 2007
          • 67

          #5
          No...
          i am doing like this:-



          if (ctr<=0)
          {
          alert('Please Check the story to edit');
          return false;
          }
          else if (ctr>1)
          {
          alert('Please Check only one story to edit');
          return false;
          }

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by nitindel
            No...
            i am doing like this:-



            if (ctr<=0)
            {
            alert('Please Check the story to edit');
            return false;
            }
            else if (ctr>1)
            {
            alert('Please Check only one story to edit');
            return false;
            }
            What about if (ctr == 1)?
            use else instead of else if (ctr>1)...

            Comment

            • nitindel
              New Member
              • Dec 2007
              • 67

              #7
              in the else part i am redirecting to another page like this:

              else
              {
              document.manage contribution.ac tion = "addcontributio n.asp?action=Ed it";

              }

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                Originally posted by nitindel
                in the else part i am redirecting to another page like this:

                else
                {
                document.manage contribution.ac tion = "addcontributio n.asp?action=Ed it";

                }
                oh! I'm sorry.. i didn't read the last line...

                But, where's the problem....?
                Paste the full code... may be then I cud find the solution..

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by hsriat
                  You won't get any better answers by repeating the question..
                  Too right. Merged the threads. nitindel, please don't double post your questions.

                  Comment

                  • nitindel
                    New Member
                    • Dec 2007
                    • 67

                    #10
                    Hi ...
                    Here is the Full Javascript code.......

                    [code=javascript]function Edit()
                    {
                    var ctr=0;

                    for (i=0;i<document .managecontribu tion.checkmanag e.length;++i)
                    {
                    if(document.man agecontribution .checkmanage[i].checked)
                    {
                    ctr=ctr+1;
                    }

                    }
                    if (ctr<=0)
                    {
                    alert('Please Check the story to edit');
                    return false;
                    }
                    else if (ctr>1)
                    {
                    alert('Please Check only one story to edit');
                    return false;
                    }
                    else
                    {
                    document.manage contribution.ac tion = "addcontributio n.asp?action=Ed it";


                    }

                    }[/code]





                    and it is called as :

                    <input name="submit" type="submit" class="buttons" onclick="javasc ript:return Edit()" value="Edit" />



                    I once again repeat the problem.....

                    I make the grid Dynamicaally in ASP using VBScript.......

                    and then clicking on the checkbox and then ob edit button redirects to another page with that corresponding record details ......

                    i have an alert that please select one story at a time.....

                    and a required alert as that "Please select the Story to Edit"


                    Now if i have more than one record in the grid...it is working fine....

                    But when only one row is populated...in the grid...it throws error...
                    "Please select the story to Edit" even if i have selected the checkbox(Story) to edit.....

                    Please let me know what possible error can it be...

                    Tonite i have to complete this module......
                    Thanks a lottttttttttttt ttttttttttt in advance....
                    Last edited by acoder; Feb 22 '08, 08:00 AM. Reason: changed bold to code tags

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      BTW, why are you using Checkbox if you have to allow user to select one of the stories at a time?..
                      Use radio buttons...
                      [CODE=javascript]function Edit()
                      {
                      var ctr=0;

                      for (i=0;i<document .managecontribu tion.checkmanag e.length;++i) {
                      if(document.man agecontribution .checkmanage[i].checked) {
                      ctr++;
                      }
                      }
                      if (ctr<=0) {
                      alert('Please Check the story to edit');
                      return false;
                      }
                      else if (ctr>1) {
                      alert('Please Check only one story to edit');
                      return false;
                      }
                      else {
                      document.manage contribution.ac tion = "addcontributio n.asp?action=Ed it";
                      return true;
                      }
                      }[/CODE]

                      Comment

                      • nitindel
                        New Member
                        • Dec 2007
                        • 67

                        #12
                        I am using Check box because i have a delete option also...which can select multiple records and delete them at one GO.......

                        Comment

                        • hsriat
                          Recognized Expert Top Contributor
                          • Jan 2008
                          • 1653

                          #13
                          Originally posted by nitindel
                          I am using Check box because i have a delete option also...which can select multiple records and delete them at one GO.......
                          tell me... is the code working?
                          Last edited by acoder; Feb 22 '08, 07:59 AM. Reason: sorry, only English allowed

                          Comment

                          • nitindel
                            New Member
                            • Dec 2007
                            • 67

                            #14
                            Yup..........!! !!!!!!!

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              nitindel, the proper way to use code tags is as follows:

                              &#91;CODE=javas cript]
                              Your JavaScript code here
                              [/code]

                              PS. glad to see that you've got it working.

                              Comment

                              Working...