如何将checkboxlist项添加到文本框中 [英] How to add checkboxlist items to a textbox

查看:191
本文介绍了如何将checkboxlist项添加到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个checkBoxList,你是怎么听说我们的媒体,传单,学校和其他。

我有一个asp文本框,我想存储被检查的值。 />
如果用户选中了媒体,则媒体被添加到文本框中。

如果他没有检查学校,那么媒体和学校将被添加到文本框中。

如果他没有检查其他,则文本将在媒体和学校中显示,并且用户可以添加不属于复选框列表的其他值。

如果用户取消选中其他,则值媒体和学校将在文本框中。



如果可以通过 out 页面进行回发?



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: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

推荐答案

查看以下插件:





[选择JS ^ ]



看多下选择,它确实如此我想你想做。
Check out the following plugin:


[Chosen JS^]

Look under multiple select, it does what I think you want to do.


让我们使用 jQuery ,因为你不想做回发。尝试使用以下代码



HTML代码

Let's use jQuery as you don't want to do postback. Try with below code

HTML code:
<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代码


Javascript code:

<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(' 点击 :复选框'功能(){
if
('#ChBMedia').on('click', ':checkbox', function() { if (


这篇关于如何将checkboxlist项添加到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆