vchris Posted April 10, 2007 Share Posted April 10, 2007 Is there a way I can check a checkbox when I only know part of the name? For example I could have many checkboxes and they would all start with "email_" and then the username. I have a query to populate this checkbox. I can't have the form processing done after the query since when the page is reloaded it'll still show the records before I update. This is an approval all function which I send an email to all users approved. So what I want is when I press Approve All that all checkboxes are checked with javascript. This page is done in coldfusion if you know of another way of doing this let me know.EDIT: Please delete this post. I found the answer. Link to comment Share on other sites More sharing options...
aalbetski Posted April 10, 2007 Share Posted April 10, 2007 I had a similar situation where I needed to check the end of the control name, it was complicated by the fact that using Infragistics controls, they prepend a whole bunch of stuff to the control name as well. Here is one way: function CheckCheckBoxes() { re = new RegExp("^email_") e = new Enumerator(form1.elements) for (;!e.atEnd();e.moveNext()) { x = e.item(); if (x.name.match(re)) { // form element found matching the name "email_" at the beginning } } } Link to comment Share on other sites More sharing options...
vchris Posted April 10, 2007 Author Share Posted April 10, 2007 I could've used regexp but it was way simpler. The names were all the same, only the value was different. So I used a script to check them all before the form reloaded. Works great Link to comment Share on other sites More sharing options...
jesh Posted April 10, 2007 Share Posted April 10, 2007 After some searching around to see why I didn't know about the Enumerator object in javascript, I discovered that it isn't part of javascript. It's part of Microsoft's JScript so it'll only work in IE.Another way to do what aalbetski posted could be like this: function CheckCheckBoxes(){ var re = new RegExp("^email_"); var inputs = document.getElementsByTagName("input"); var input; for(var i = 0; i < inputs.length; i++) { input = inputs[i]; if(input.type == "checkbox") { if(input.id.match(re)) { input.checked = true; break; } } }} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now