Dynamically attach onchange script to checkboxes in catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 05:59 AM
I'm wondering if this is possible. I would like to detect a change to the value of any of a set of checkboxes, and run a script that validates what/how many are checked in order to determine whether the requirements for the form are meant. I would like to be able to display that visually, rather then the user having to wait until an on-submit for the validation to occur/message to be displayed.
I would like this to be dynamic so that if there are 10 checkboxes, I don't have to write 10 seperate onChange client scripts. I'm thinking one on-load script, with a list of the 10 checkboxes for it to loop through and attach a script or function to them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 06:47 AM
Chris,
You can do it by actual element id, by using $("element id") to access that element.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 07:22 AM
I have a solution. The visible checkbox did not have a change script, so I added an eventListenter to that. I think I'll be able to get what I'm after.
Due to the risk with manipulating the DOM, I don't want to post my actual code, but the above should get people started if they want to pursue it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 07:29 AM
Yeah that is what I am saying, you can observe an element for the events using id and do your manipulation accordingly. This link will be helpful
Prototype v1.7.3 API documentation | Event.observe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 08:02 AM
Hi Chris,
That's the way to go. Use Prototype as Abhinay has mentioned. I've done it a couple of times and it works like a charm.
Cheers
Greg
