Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a checkBoxList with "how did you hear about us" media, Flyer, School and Other.
I have an asp textbox where I want to store the values that are checked.
If the user checked media then media is added to the textbox.
If he than checked school then media and school is added to the textbox.
if he than checked other then the text will be visible with media and school in it and the user can add the other values that are not part of the checkboxlist.
If the user unchecked other then the values media and school will be in the textbox.

if that can be done without the page being postback?

ASP.NET
<asp:CheckBoxList ID="ChBMedia" runat="server">
                        <asp:ListItem>Media Article (TV/Radio/Newspaper) </asp:ListItem>
                        <asp:ListItem>Flyer</asp:ListItem>
                        <asp:ListItem>School (for student volunteers) </asp:ListItem>
                        <asp:ListItem>Other</asp:ListItem>
                    </asp:CheckBoxList> 


What I have tried:

what i have tried is not worth sending up
Posted
Updated 2-Mar-16 17:25pm

Check out the following plugin:


[Chosen JS^]

Look under multiple select, it does what I think you want to do.
 
Share this answer
 
Let's use jQuery as you don't want to do postback. Try with below code

HTML code:
ASP.NET
<asp:checkboxlist id="ChBMedia" runat="server" xmlns:asp="#unknown">
	<asp:listitem>Media Article (TV/Radio/Newspaper) </asp:listitem>
	<asp:listitem>Flyer</asp:listitem>
	<asp:listitem>School (for student volunteers) </asp:listitem>
	<asp:listitem>Other</asp:listitem>
</asp:checkboxlist> 
<asp:textbox id="txtMedia" runat="server" xmlns:asp="#unknown"></asp:textbox>

Javascript code:
JavaScript
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$('#ChBMedia').on('click', ':checkbox', function() {
    if ($(this).is(':checked')) {
        // handle checkbox check
		var value = $(this).text();
        alert(value);

		// append value to text box
		if($("#txtMedia").val() == "")
		{
			$("#txtMedia").val(value);
		}
		else
		{
			$("#txtMedia").val($("#txtMedia").val() + ", " + value);
		}
    }
});
</script>

Above javascript code will append value to textboxe with comma separated onclick of checkbox. If you have different requirement then you can change the logic in javascript.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900