RSS Forums RSS
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2805 | Replies: 4 | Thread Tools  Display Modes
Join Date: Nov 2007
Posts: 4
Reputation: xmassey is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xmassey xmassey is offline Offline
Newbie Poster

Checkbox value appended to textbox

  #1  
Nov 21st, 2007
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
Last edited by xmassey : Nov 21st, 2007 at 3:12 am.
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:51 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC