You must Sign In to post a response.
  • Category: JavaScript

    The code is not working want to know how to rectify it

    <script src="Script/jquery-1.11.3.min.js"></script>
    <script>
    $(document).ready(function () {
    debugger;
    $("#btn1").click(function () {
    $v = $("#txt").val();
    for (i = 0; i < $v; i++) {
    var box = $('<input type="checkbox" class="chkbx" name="chkbx" value="Option' + i + '">Option ' + i + '<br/>');
    $("#display").append(box);
    }
    });

    $(document).on("change", ".chkbx", function () {
    debugger;
    $("#show").val("");
    var selected = [];
    $(".chkbx:checked").each(function () {
    selected.push($(this).val());
    });
    $("#show").val(selected.join(", "));
    });
    });
    </script>
    </head>
    <body>
    <table>
    <tr>
    <td><input type="text" id="txt" name="text" /></td>
    <td><button id="btn1">Create</button></td>
    </tr>
    <tr>
    <td><div id="display"></div></td>
    </tr>
    <tr>
    <td><input type="text" id="show" name="show" placeholder="Display Selection.."/></td>
    <td><p></p></td>
    </tr>
    </table>

    </body>
    </html>
  • #763856
    I think you did not close the option box

    Can you check and let me know whether is it working or not?

    var box = $('<input type="checkbox" class="chkbx" name="chkbx" value="Option' + i + '"/>Option ' + i + '<br/>');

    By Nathan
    Direction is important than speed

  • #763857
    No still its not working the click event doesn't fire ,when clicked directly breakpoint goes to javascript file

    Delete Attachment

  • #763867
    Remove all code from '$("#btn1").click(function ()' and give alert in jQuery to check if code flow properly, I think opetion button give you error
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763889
    Hai Priyanka,
    It seems that some other script is clashing and the control is not getting to this script.
    You can try by moving

    <script src="Script/jquery-1.11.3.min.js"></script>

    To the below of your script.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #763925
    Hi

    First

    Check your references this line correct or not


    <script src="Script/jquery-1.11.3.min.js"></script>


    Second
    just put one alert box only inside document ready working or not then you try step by step then you can easily find the issues.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764143
    Hi Priyanka,

    Just replace your for loop declaration with following line:

    for (i = 0; i < $v.length; i++)

    because $v holds text inputted in textbox with id="txt" so it will be a string of characters, so you have to iterate it with regards to its each and every character.

    Hope this will help you.

    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments