I have a group list as select like that:
<select id="groups">
<option value="g1">G1</option>
<option value="g2">G2</option>
<option value="g3">G3</option>
</select>
I have a contact list which basically contains:
Name = group
============
Casper G1-G2-G3
Andy G1-G2
Mark G2-G3
When the user check the checkbox for Casperand click Edit button so G1-G2 and G3 should be highlighted (Selected) in the group list. When I get the value of the group field in the contact list, all of the three groups come with comma "G1-G2-G3".
Your help is highly appreciated.
Thanks,
Some tips, I believe it’s good for you to solve this problem yourself 😉
Seems that
Casperbelongs to multiple groups, so you should setmultiple="true"to yourselectWhen you check
Casper, retrieve the group data associated with him, say["g1", "g2", "g3"]. Loop over this list, and set each option with the value toselected.If you want to support IE6, you need also add a class, say
selectedto theselectedoption.The CSS rule
{ option.selected: background: yellow}will do the trick.If you only target on modern browser,
option[selected]{ xxx }works well.