Click here to Skip to main content
15,886,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use jquery to append a text to a para. Text is taken from an input text. My code is as follows:

XML
<head runat="server">
    <title></title>
    <script src="jquery-1.11.1.js" type="text/javascript"></script>
    <script>

        var x = $("input:text").val();
       $(document).ready(function () {
            $("#button1").click(function () {
                $("p").append(x);
            })
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p id="Messages">Messages displayed here:</p>
    </div>
        <div>
            <input id="Text1" type="text" />
                 <br />
            <br />
            <button id="button1">Submit</button>

        </div>


It I give a fixed valued to var x such as var x= "My text"; it works and text is appended. My effort here is to take text from input from input id= Text1. Apparently I am making mistake in getting the value of text from input.

Please help.
Posted

1 solution

Fiddle for this[^]
Please check the above fiddle created based on the anticipation of what you need.
Hope this helps.
Thanks.
 
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