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 5 of 5
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts

    check box function

    Is there any way to apply an effect only to the particular element that calls the javascript function even if there are other elements with the same name

    basically I'm customising an asp script that writes out, amongst other things a series of check boxes and I want to apply an onClick to those checkboxes, however they all have the same name so when try to uncheck the element it unchecks them all

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Location
    In front of this computer. (Where else?)
    Posts
    442
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why are you using the same name for them? why not use different dynamic names like box1, box2, etc That's the solution I would use. Hang around a little while though, someone may know how to do it the way you want.
    Tomorrow is the first day of the rest of your life... What have you done today?
    Tutorials
    Web: w3schools, htmldog General tips: Hardware, Networking

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, you can give them a different id, then you can style them different in your CSS, or approach them easily by javascript.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When you have check boxes with the same name you can reference them using an interation (just like referencing an array item). So for instance if you want to "check" the first checkbox you could do this:
    document.form_name.checkbox_name[0].checked=true

    If you have not assigned a name to your form and it is the only one on the document you can reference it this way:
    document.forms[0]

    If your elements don't have a name and you need to reference then you can do it this way:
    document.forms[0].elements[0]

    This would reference the first element in the first form of your document. If you have two forms and you want to reference the first element in the second form then you would do this:
    document.forms[1].elements[0]

    Hope this helps and good luck.

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Quote Originally Posted by tboss132
    Why are you using the same name for them? why not use different dynamic names like box1, box2, etc That's the solution I would use. Hang around a little while though, someone may know how to do it the way you want.
    I didnt write the original asp script and its a beast to modify, obviously if there is no other alternative then I'll have to, I was just interested to see if there was a quicker way


  •  

    Posting Permissions

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