Hi,
I have a list of check boxes with group id's and group names for different locations. In my form, I have a groups field which needs to be populated with the group id's selected. So the text filed will eventually be a comma seporated list of group id's for a sql query, like
"'group1', 'group2', 'group3'"
If a tick is removed from any checkbox, then the associated group id is removed.
I'm not interested in iterating through the check values after the form has ben submitted, as the checks are not part of the form, and can be drilled down into sub groups.
Problem is ... er .... it dosn't work.
the javascript is as follows:
the example html is as follows:
Please help!
Many thanks for viewing my post.
All the best,
kinnon
I have a list of check boxes with group id's and group names for different locations. In my form, I have a groups field which needs to be populated with the group id's selected. So the text filed will eventually be a comma seporated list of group id's for a sql query, like
"'group1', 'group2', 'group3'"
If a tick is removed from any checkbox, then the associated group id is removed.
I'm not interested in iterating through the check values after the form has ben submitted, as the checks are not part of the form, and can be drilled down into sub groups.
Problem is ... er .... it dosn't work.
the javascript is as follows:
Code:
<script type="text/javascript">
<!--
function modifyText(id,val){
var tar=document.getElementById(id);
cbid = 'cb_'+val; // the checkbox id
if(cbid.checked){
// checkbox is checked, so add the text to the input text
tar.value=val+', '+tar.value;
}else{
tar.value=tar.value.replace('/'+val+',/','');
}
}
// -->
</script>
the example html is as follows:
Code:
<input type="text" name="filt_groups" id="filt_groups">
<table>
<tr>
<td class="td1"><input type="checkbox" name="cb_ABER" value="ABER" onClick="modifyText('filt_groups','ABER');"></td>
<td class="td1">ABER</td>
<td class="td1">Aberdeen</td>
</tr>
<tr>
<td class="td1"><input type="checkbox" name="cb_BEL" value="BEL" onClick="modifyText('filt_groups','BEL');"></td>
<td class="td1">BEL</td>
<td class="td1">Belfast</td>
</tr>
<tr>
<td class="td1"><input type="checkbox" name="cb_BHAM" value="BHAM" onClick="modifyText('filt_groups','BHAM');"></td>
<td class="td1">BHAM</td>
<td class="td1">Birmingham</td>
</tr>
</table>
Please help!
Many thanks for viewing my post.
All the best,
kinnon