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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regarding checkboxes

    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
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Plz anyone reply me..its urgent

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Bumping after only 13 minutes seems rather premature. You need to be more patient - this forum is not some sort of public enquiry service with people standing by 24/7 to answer your questions.

    Also you have double posted in Javascript Framewoks also. See forum Rule 1.2:

    1.2) Do not crosspost - CodingForums.com is divided into various categories. When initiating a thread, always locate the most appropriate category, and post your question only ONCE, in that category. Do not post the same question in multiple categories.

    I think it would be a good idea if you had a look at

    http://www.catb.org/~esr/faqs/smart-questions.html

    Particularly:
    Don't flag your question as “Urgent”, even if it is for you.
    That's your problem, not ours. Claiming urgency is very likely to be counter-productive: most forum users will simply delete such messages as rude and selfish attempts to elicit immediate and special attention.

    In short, you are much more likely to get a response if you show some respect for the forum rules, guidelines and conventions.
    Last edited by Philip M; 05-08-2009 at 12:25 PM.

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually Mr philp i have posted it on 8th of may.But till now i didnt get any solution.
    Main problem is this, here no one is there to give the solution but everyone is there to give the suggestion.
    And if you can give the solution of my question then plz do that because i no well how i have to post and what i have to write.Coz i have posted the query on 8th and till now no response.

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually mr. philip i have posted my query on 8th of may and till now i didnt recieve the solution.
    Main problem is that,here no one to give the solution but everyone to give the suggestion.
    So i dont need the suggestion ,i need the solution.
    So plz keep your suggestion wid you and if you have the solution of mine query the please give that.I know what i have posted and what i have used.i didnt be selfish.my query is been posted on 8th may and today is 11th may and solution is null.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>untitled</title>
    <script type="text/javascript">
    
    function oneChecked()
    {
       var box, n = 1;
       while (box = document.getElementById('chkBankServices' + n++))
       {
          if (box.checked)
          {
             return true;
          }
       }
       alert('Please select at least one service to submit.');
       return false;
    }
    
    </script>
    </head>
    <body>
    <form id="bankform" onsubmit="return oneChecked()">
    <input type="checkbox" id="chkBankServices1" name="bs1">... some service<br />
    <input type="checkbox" id="chkBankServices2" name="bs2">... some service<br />
    <input type="checkbox" id="chkBankServices3" name="bs3">... some service<br />
    <input type="checkbox" id="chkBankServices4" name="bs4">... some service<br /><br />
    <input type="submit" />
    </body>
    </html>
    ids must be unique (and, no such thing as document.getElementsById).
    Just have your asp give the checkboxes consecutive ids ("chkBankServices1", "chkBankServices2", ....). That'll give the loop something to look for.

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks mr. adios,
    but my problem is i am fetching the data from database like this:
    *********Java Script******
    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;
    }
    else{
    document.frmCustomerUpdation.cmd.value='btnUpdate';
    document.frmCustomerUpdation.submit();
    }

    **********HTML************


    <td><b>Banking Services:</td>
    </tr>
    <%

    //System.out.println("vecResult.size--------"+vecResult.size());
    if(vecResult != null)
    for (int i = 0; i < vecResult.size(); i++) {
    BankService bs = (BankService) vecResult.elementAt(i);
    for (int j = 1; j < vecUpdateCustomerID.size(); j++) {
    BankService objCustomerService = (BankService) vecUpdateCustomerID.elementAt(j);
    //TBD:
    if (objCustomerService.getServiceID() == bs.getServiceID()) {
    System.out.println(bs.getServiceID() + " "
    + objCustomerService.getServiceID());
    %>
    <tr>
    <td colspan="2"><input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>" CHECKED><%= bs.getServiceDesc()%>
    </td>
    </tr>
    <%
    break;
    }
    }
    }
    boolean blnSelected = false;
    if(vecResult != null)
    for (int i = 0; i < vecResult.size(); i++) {
    BankService bs = (BankService) vecResult.elementAt(i);
    for (int j = 1; j < vecUpdateCustomerID.size(); j++) {
    BankService objCustomerService = (BankService) vecUpdateCustomerID
    .elementAt(j);

    if (objCustomerService.getServiceID() == bs.getServiceID()) {
    blnSelected = true;
    break;
    }
    }
    if (!blnSelected) {
    %>
    <tr>
    <td colspan="2"><input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>
    </td>
    </tr>
    <%
    } else
    blnSelected = false;
    }
    %>

    So how i can give the ids different..please suggest me.

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    That's an asp question, not javascript. But, just a guess ...

    <td colspan="2"><input type="checkbox" id="chkBankServices<%=idnum%>" name="<%=bs.getServiceID()%>" CHECKED><%= bs.getServiceDesc()%>

    ... or something like that, where idnum starts at 1 and then increments after each write. So you end up with:

    Code:
    .....
    + objCustomerService.getServiceID());
    %>
    <tr>
    <td colspan="2"><input type="checkbox" id="chkBankServices1" name="<%=bs.getServiceID()%>" CHECKED><%= bs.getServiceDesc()%>
    </td>
    </tr>
    <%
    break;
    }
    }
    }
    boolean blnSelected = false;
    if(vecResult != null)
    for (int i = 0; i < vecResult.size(); i++) {
    BankService bs = (BankService) vecResult.elementAt(i);
    for (int j = 1; j < vecUpdateCustomerID.size(); j++) {
    BankService objCustomerService = (BankService) vecUpdateCustomerID
    .elementAt(j);
    
    if (objCustomerService.getServiceID() == bs.getServiceID()) {
    blnSelected = true;
    break;
    }
    }
    if (!blnSelected) {
    %>
    <tr>
    <td colspan="2"><input type="checkbox" id="chkBankServices2" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>
    </td>
    </tr>
    ........


  •  

    Posting Permissions

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