-
You do realize by 'gay' I mean a man who has sex with other men?
Okay Tech Question... JavaScript Related (I Think)
I have an admin area that has a bunch of check boxes in it, now usually i just select each option manually as im going through the various image sets that i need to categorize however, recently im noticing that more and more im having to select all of the options for image sets.
Does anyone know of a way i can put a JavaScript in this pages HTML template so that i only have to check a single box and in turn, that will make check marks appear in all of the other boxes on the same page? Is this even possible?
Regards,
Lee
-
Moderator
I've seen a select all option with a list of things ... which is what you want to have happen.
-
Gay Marriage - It's our Pearl Harbor.
Something like this should work. I haven't tested it but give it a go and if it's funky, I'll try to tweak it for you. It will toggle all of the checkboxes in a form based on whichever state they currently are in, so you can use it whichever way you want.
You need to put this in the page code:
<script type="text/javascript">
function ToggleCheckboxes(x) {
for(var i=0,l=x.form.length; i<l; i++) {
if(x.form[i].type == 'checkbox' && x.form[i].name != 'toggleAll') {
x.form[i].checked=x.form[i].checked?false:true
}
}
}
</script>
Then put this in your form (I assume you have a form with checkboxes, which is where you want to change the checkboxes' status:
<form> (you should already have this line on the page somewhere)
<input type="checkbox" name="toggleAll" onclick="ToggleCheckboxes(this)" /> (Toggle checkboxes)<br />
</form> (don't add an extra line like this, just here to show you the above INPUT line goes inside the form boundaries)
Hope it works
Kevin
Hmm, doing a preview I see the forum doesn't like tabs and whitespace, so all of my indentations and alignment of brackets didn't do a thing! Oh well, javascript doesn't care about such things, it's only to make it prettier and easier to read for us mere mortals.
-
You do realize by 'gay' I mean a man who has sex with other men?
Okay cool ill give that a shot and see what happens
When posting any type of code, if you use the BB tag [ code ] and [ / code ] without the spaces it should let you post anything
Regards,
Lee
-
You do realize by 'gay' I mean a man who has sex with other men?
Its kinda working, going to play with it a little more though as my original programmer made all of the checkboxes part of the php code and they are all dynamically generated, appreciate the help again Kevin
Regards,
Lee
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks