as for group #2:
<img onclick="this.className=(t
...repeat
Main Topics
Browse All TopicsI have groups of images that I'd like people to be able to select.
Image Group One:
There's four images, 3 are assigned the css class "select-off", one is assigned the css class "select-on". I have corresponding CSS written, but that's not relevant to what I'm trying to do right now. What I want is when someone clicks on one of the images, the css class is swapped. This will in turn swap the other classes for the other images as well. So only one image from the group can be selected at a time. This works exactly like the radio button of an html form.
Image Group Two:
there's four images, 3 are assigned the css class "select-off", one is assigned the css class "select-on", just as the group described above. The difference with this group, is that multiple images can be selected within the same group. Clicking the image will swap the class from the current class to the opposite. Clicking again will swap again. These work exactly like selecting/unselecting checkboxes in an html form.
Since all of the images in the different groups are different from each other, I need to be able to swap classes, not images. Also, I have many different instances of both Group One and Group Two on the same page.
Ive tried adjusting many different javascripts I've found around the Net, but with no luck. I know this is very simple, and I've come close to what I want on my own, but my js skills just arent very good. Does anyone know of a script available that I can use for this without modifications? Or does anyone perhaps already have a script they care to share? Thanks :)
A final quick note, selecting an image should NOT refresh the page. Links that require href="#" in the tag to operate properly wont help me, as that would conflict with the way I have the page already setup. I need the link tag that wraps the image to not contain href at all. The images are being selected, but not actually linking to anything.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thank you cwolves. This is a great help! i'm having a bit of trouble with it though. I changed the spans to images, and added the code in your second post to the "checkbox-style" images, but they're acting the same as the "radio-style" images. Also, if any other image is clicked in the page, it clears the selection of all image groups. I've attached the code snippet I'm using (i've used the same image as placeholders here, but they will actually all be different images, but same sizes):
the problem is with the prepItems function call which is basically preparing ALL images on the page for this.
Try calling it once on each div that you want to function like this:
prepItems(document.getElem
where 'parentDiv1' is the ID of a 'radio-style' div. You need to change the id's from 'buttons' to 'buttons1', 'buttons2', etc.
thanks a million cwolves, it works perfectly now in all browsers. I'm still having trouble with the checkbox-style images though. they act the same as the radio-style buttons instead of allowing toggling back and forth regardless of what other images are selected.
I put the code you gave in the img tag like this:
<img src="images/customize-repe
is this not correct? I noticed the "?" in the code snippet, never seen that before so I'm not sure if that's suppose to be a ? or if its a character that my pc isnt recognizing.....
I've run into another problem and posted it as a different question with new points. i thought you might want to take a look since you were the one to help with the first part of this ;)
The new question is located here:
http://www.experts-exchang
Business Accounts
Answer for Membership
by: cwolvesPosted on 2008-05-05 at 15:12:35ID: 21503443
done with spans because it's easier for now, just convert to images:
Class'); lass');
SPAN');
entsByTagN ame('SPAN' ));
<style>
span{
border:1px solid blue;
}
.class1{
background-color: yellow;
}
.class2{
background-color: gray;
}
</style>
<div instanceClass="class1" generalClass="class2">
<span id="initial">test1</span>
<span>test2</span>
<span>test3</span>
<span>test4</span>
</div>
<script>
function selectItem(ev){
ev = ev || window.event;
var item = ev.target || ev.srcElement;
var par = item.parentNode;
var iCls = par.getAttribute('instance
var gCls = par.getAttribute('generalC
var child = par.getElementsByTagName('
for(var i=0; i<child.length; i++){
child[i].className = child[i]==item?iCls:gCls;
}
}
function prepItems(items){
for(var i=0; i<items.length; i++){
items[i].onclick = selectItem;
}
}
prepItems(document.getElem
</script>