Click here to Skip to main content
15,899,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This flashes the correct name-drink li but does not save the "items" to HTML at the <ul class="orders">
ASP.NET
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var name = $('#<%= name1.ClientID %>').val();
            var drink = $('#<%= drink1.ClientID %>').val();
 
            $('#<%= add_order.ClientID %>').on('click', function () {
                 var items="<li>name: " + name + ", drink: " + drink + "</li>";
                 $('.orders').html(items);
                 //$('.orders').append(items);//these two do the same thing
             });
        });
    </script>

    <h2>Coffee Orders</h2>
    <ul class="orders">
        
    </ul>
    <h4>Add a Coffee Order</h4>
    <p>Name:<asp:TextBox ID="name1" runat="server"></asp:TextBox></p>
    <p>Drink:<asp:TextBox ID="drink1" runat="server"></asp:TextBox></p>
    <asp:Button ID="add_order" runat="server" Text="Add!" />
Posted

1 solution

Change your code this way
C#
$(function () {
            $('#<%= add_order.ClientID %>').on('click', function () {
                 var name = $('#<%= name1.ClientID %>').val();
                 var drink = $('#<%= drink1.ClientID %>').val();
                 var items="<li>name: " + name + ", drink: " + drink + "</li>";
                 $('.orders').append(items);
                 return false;
             });
});


Regards..
 
Share this answer
 
v3
Comments
Teledextri 3-Dec-14 8:39am    
This does display but with a blank li "name: drink: "
Thanks7872 3-Dec-14 9:03am    
Its working perfectly. Just copy paste whole code. And than observe the change.
Teledextri 3-Dec-14 9:09am    
Not working perfectly it give a blank li
Thanks7872 4-Dec-14 1:17am    
Update the question with the code you are currently having. Both mark up and Javascript.

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