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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    When validating checkboxes with different names, numbers in names kill the form

    When validating checkboxes with different names, numbers in names kill the form

    Hello,

    I have to create a validation for a number of checkboxes that have different names (I know it's best to have the same names for each, and I would love to... But I'm working with someone else's system on this one! ). I can get it working if the names are simple text like in the below 'fred' or 'george' but when the names are actually these whacky code numbers that the system uses, it fails.

    See examples below of what fails and what works. Any suggestions would be most welcome!

    Does Not Work:
    if (theForm.00N30c2Mw.checked == false && theForm.00N302wD.checked == false)
    {
    alert ('Please select at least one checkbox');
    return false;
    }

    Does Work:
    if (theForm.fred.checked == false && theForm.george.checked == false)
    {
    alert ('Please select at least one checkbox');
    return false;
    }

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    name shoud strat with alpha character but
    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" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    function Ck(){
    if (!document.getElementsByName('00N30c2Mw')[0].checked&&!document.getElementsByName('00N302wD')[0].checked)
    {
    alert ('Please select at least one checkbox');
    return false;
    }
    }
    </script></head>
    
    <body >
    <form >
    <input type="checkbox" name="00N30c2Mw" />
    <input type="checkbox" name="00N302wD" /><input type="button" name="" value="Tst" onclick="Ck();" />
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It works like a charm now.


    You are my hero


    Have a good week.


  •  

    Posting Permissions

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