Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello All,
I am tring to implement a small texteditor.
ASP.NET
<asp:TextBox ID="txtEnquiryText" runat="server" TextMode="MultiLine" CssClass="text_sms_panel"></asp:TextBox>
<div class="Item_Container">
<div class="test tag">{name}</div>
<div class="test tag">{course name}</div>
</div>

when i click on tag(eg.{name}), the clicked tag should get append to text of textbox.
it is working fine. but when i give backspace and erase the text ,on next click the text of textbox doesn't changes. and backspaced text still there when i debug the jquery code
JavaScript
$('.tag').click(function () {
                var tag = this.innerHTML;
                var smstext = $('#<%=txtEnquiryText.ClientID %>').text();
                smstext = smstext + tag;
                $('#<%=txtEnquiryText.ClientID %>').text(smstext);
            });
Posted
Comments
ashok rathod 16-Jul-14 7:01am    
you are erasing text of your textbox or div ?
[no name] 16-Jul-14 7:09am    
textbox

1 solution

Please check with using val() method to set or getting the value for the textbox rather than using text() method as below :-

NOTE : This text() method works on both HTML and XML documents. Cannot be used on input elements. For input field text use the val attribute.

JavaScript
$(function () {
            $('.tag').click(function () {
                var tag = this.innerHTML;
                var smstext = $('#<%=txtEnquiryText.ClientID %>').val();
                smstext = smstext + tag;
                $('#<%=txtEnquiryText.ClientID %>').val(smstext);
            });
        });


Hope this will be of help to you.
 
Share this answer
 
v2
Comments
[no name] 16-Jul-14 7:24am    
thanx..thanx a lot..it works fine
SRS(The Coder) 16-Jul-14 8:16am    
wl cm always :-)

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