...

View Full Version : check box function



NancyJ
03-18-2005, 01:42 PM
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

tboss132
03-18-2005, 01:55 PM
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.

martijntje
03-18-2005, 01:56 PM
Well, you can give them a different id, then you can style them different in your CSS, or approach them easily by javascript.

requestcode
03-18-2005, 02:09 PM
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.

NancyJ
03-18-2005, 02:39 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum