Hello,
I am trying to print all the selected checkbox values to a textbox separated by commas (, ). However, the first value in the textbox always starts with a comma (, ) i.e. (, one, two, three) etc. My current script trys to check if the first 2 characters (substring) are ", " (comma then space) then attempts to remove them. However this hasn't worked and I have no idea what to try next.
<head>
<script type="text/javascript">
function list(c,n,z) {
s=document.form.marktext.value;
if (c.checked) {
if (s.indexOf(n)<0) s+=', '+n;
} else {
s=document.form.marktext.value.replace(', '+n,'');
}
z=", ";
if (s.substring(2) == z) s=s.substring(2);
document.form.marktext.value=s;}
</script>
</head>
<body>
<form name="form">
<input type="text" value="" name="marktext"><br>
<input type="checkbox" name="mark" onclick="list(this,'Word')">Word<br>
<input type="checkbox" name="mark" onclick="list(this,'Type')">Type<br>
<input type="checkbox" name="makr" onclick="list(this,'Other')">Other<br>
</form>
</body>
Thanks
Chris