简体   繁体   中英

I already have 3 checkboxes and 1 textbox in asp.net webform when i check 1and 2 checkbox then result in textbox will be 1,2

I already have 3 checkboxes and 1 textbox in asp.net webform when i check 1and 2 checkbox then result in textbox will be 1,2

I have the following code :

<script type="text/javascript">
    function Test(control, value) {
        var str = '';
        if (control.checked) {
          str = value + '\n' + $('#<%=txtTest.ClientID %>').val();
        }
        else {
            str = $('#<%=txtTest.ClientID %>').val().replace(value + '\n', '');  
        }
        $('#<%=txtTest.ClientID %>').val(str);
    }
</script>

to do this......

But the problem in this code ...was when i check 3 and 2 checkbox then result in the textbox is 3,2,

But i want it appear as 2,3 only ...

Can anybody reedit this code ....... ??????

I would be thank ful to u ..............

如果您只是反转输出怎么办?

$('#<%=txtTest.ClientID %>').val().split(",").reverse().join(",");

This function is triggered when user clicks check box. So if you click 2 & 3 by this order, them there is everything right?

So user "each" sentence:

<script type="text/javascript">
    function Test(control, value) {
     var str = '';
     $('#<%=txtTest.ClientID %> :checked').each(function() {
       str = str + ', ' $(this).val();
     });
     $('#<%=txtTest.ClientID %>').val(str);

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM