Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to check that atleat one checkbox is selected or not

    Hello guys,
    Plz if anyone can help me to solve my problem.
    I am stuck wid a problem of javascript.
    My problem is that i am using checkboxes whose values is comming from database.Its name is same but name is fetching like:
    <input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>
    through this i am getting the values from the database.
    Now i have to validate that at least one checkbox should be selected..

    So plz anyone help me how i can do that.
    If i am giving like this the javascript code:
    var services = document.getElementsById( 'chkBankServices' );
    if(!(services[0].checked) && !(services[1].checked) && !(services[2].checked) && !(services[3].checked)
    && !(services[4].checked) && !(services[5].checked) && !(services[6].checked) && !(services[7].checked)
    && !(services[8].checked))
    { alert( "Please select at least one service to submit." );
    return false;
    }

    Its not giving any alert message.
    Is anything wrong in that.
    Plz help me...
    Thanks in advance

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi abduraooft,
    Thanks a lot but
    i have little bit different problem.that i cant give the value in HTML and the name which i am giving in HTML is like this:
    ****HTML********
    <input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>

    <td><input type="button" name="btnUpdate" value="Update" onclick="return validate()" ></td>

    And javascrpt for this is
    *********Java script**************
    function validate()
    {
    var services = document.getElementsById( 'chkBankServices' );

    if(!(services[0].checked) && !(services[1].checked) && !(services[2].checked) && !(services[3].checked)
    && !(services[4].checked) && !(services[5].checked) && !(services[6].checked) && !(services[7].checked)
    && !(services[8].checked))
    { alert( $("#chkBankServices input[type=checkbox]:checked").length > 0 );

    return false;
    }
    else{
    document.frmCustomerUpdation.cmd.value='btnUpdate';
    document.frmCustomerUpdation.submit();
    }

    }

    How to solve this

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi abduraooft
    wat happen you didnt answer me..
    plz help me

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hello plz anyone help me to solve my this problem..

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    This is not the correct forum.
    You already posted there, and subsequently ignored responses.

    regarding checkboxes

    Why do you keep complaining if you don't want answers?


  •  

    Posting Permissions

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