2

I have a jquery ui dialog with a textarea in it :

<div id="dialog">
     <textarea id="box">Hello World</textarea>
</div>

Once I open the dialog ,I could edit the textarea's content,

then when close the dialog,I want get the content that I have edited

the dialog code:
 $("#dialog").dialog({
                 autoOpen: false,
                 height: 140,
                 buttons: {
                     Confirm: function () {
                         alert($('#box').html());
                         $(this).dialog("close");
                     }
                 }
             });

In this example,the original content is "hello world",then the dialog open,I delete the "world", the strange thing is that,when I click confirm,the page alert still "hello world"

I change html() function to text(),the result still the same,so how can I get the content that I edited when close the dialog?

PS:the reason I use Html() is that I want the content write to Sql database ,keep the "<br>" or "&nbsp;"

the online example is here

1 Answer 1

3

Try using:

$("#box").val()

instead of:

$("#box").html()

If you need to have <br>s for newlines, you can do replacements such as:

$("#box").val().replace(/\n/g, "<br>")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.