2014-10-05 34 views
-1

從我搜索的內容來看,不可能在textarea中使用div標籤。任何人都可以提出一個替代方法來實現我想要實現的目標嗎?如何獲得將DIV放入TEXTAREA的效果?

我希望在下拉框中選擇的模板在文本框內加載。

Controlpanel.php

<h2><u>Edit</u></h2> 
<form action="ajax/name.php" name="edit_template_form" id="edit_template_form" method="post"> 
<select name="edit" id='edit_template_name'> 

    <?php foreach($res as $row){ 
    print "<option value=".$row['template_name']." >".$row['template_name']."</option>"; 
    } ?> 

</select><br/> 
<textarea rows="10" cols="25" name="template_edit" id="template_edit"><div id="edit_template"></div></textarea><br/> 
<button type="button" name="edit_submit" id="edit_submit">Submit</button></form> 
<div id="edit_data"></div> 

testprocess.js

$('#edit_submit').on('click', function(event) { 
    event.preventDefault(); 
    var edit_template = $('#template_edit').val(); 
    var edit_name = $('#edit_template_name').val(); 
    $.post('ajax/name.php', {edit_name: edit_name, edit_template: edit_template}, function(data) { 
     $('div#edit_template').text(data); 
    });  
    location.reload(true); 
}); 

name.php

if (isset($_POST['edit_template'])) { 
    $template_edit = $db->escape($_POST['edit_template']); 
    $template_name = $db->escape($_POST['edit_name']); 
    $user = $db->escape($user); 

    $db->update('templates', array('template_description' => $template_edit), 'template_name="'.$template_name.'" AND userID="'.$user.'"'); 

    echo $_POST['edit_template']; 
} 
+1

錯誤...只是使用文本框的值而不是div。 – Quentin 2014-10-05 19:21:54

回答

1

替換此:

$('div#edit_template').text(data); 

與此:

$('textarea#template_edit').val(data);