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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript checkbox error

    Hello all,

    I am having problems with checkboxes.
    suppose i have these checkboxe:

    <input type='checkbox' name='check[]' />
    <input type='checkbox' name='check[]' />

    then i can easily access these checkboxes using javascript
    e.g. alert(document.frm_registration['check[]'].length);

    but when i am binding checkboxes dynamically it is generating the same code as above but now i m getting undefined while accessing the checkboxes.

    hope I m able to explain my problem.. kindly help me out

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The best way to interact with form fields from JavaScript is using id rather than name.

    You'll need to give each checkbox an id in order to attach its label in the HTML and so can easily use that same id to reference the field from JavaScript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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