Unable to get Updated textarea Value

僤鯓⒐⒋嵵緔 提交于 2020-01-04 06:56:15

问题


I have a problem:

I have a textarea on my page that looks like this:

<textarea id='redactor_content' name='redactor_content' style='width: 720px; height: 320px;'>$news[3]</textarea>

Where $news[3] is a php variable that I get from MySQL. redactor_content is a WYSIWYG editor where I edit the content of $news[3]. After the content is edited, I want to pass it to mysql to update the table with the following JavaScript:

function update_news(n_id) {
    var title = $('#title').val();
    var news_body = $('#redactor_content').val();
    alert(news_body);
    $.post(
        "update.php",
        {n_id: n_id, title: title, body: news_body},
        "html"
    )};

There are 2 more variables in JS which are n_id and title. Both are working OK. But when the alert pops up with the news_body variable I see the old version of textarea (which was initially in the $news[3] variable), not the new, updated one.

I'm stuck guys. Any help is appreciated!


回答1:


most of the wysiwyg editors create a new separate section on the page (an iframe usually) that overlays the textarea they're replacing. You'd need to tell the editor to copy the data in the "fancy" graphical version back to the original form fields so your JS can get the updated version. or figure out how/where the editor is storing the overlayed version so you can grab it from there.




回答2:


There is probably some client side functionality that the redactor_content exposes to allow you to retrieve the value correctly. Something like $('#redactor_content')[0].getTextValue() or something.

That isn't the actual code mind you, just an example of how it possible works.




回答3:


Thanks for the help guys, the answer to my question is :

need to replace this line :

var news_body = $('#redactor_content').val();

with this line :

var news_body = $('#redactor_content').elrte('val');


来源:https://stackoverflow.com/questions/8070414/unable-to-get-updated-textarea-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!