I currently have a textarea that will set the input. But I am trying to save the text entered to a database table, and output that text to a div below the textarea. I'm not the most efficient PHP programmer so I'm hoping someone can shed some light.
Here's what I have for markup and JS:
<div id="container">
<div id="main">
<div id="top-box">Tell us what you're thinking...</div>
<form method="post" action="#">
<p>
<label for="boxText">
<textarea id="boxText"></textarea>
</label>
</p>
<p>
<input type="submit" name="submit" value="Submit" />
</p>
</form>
</div><!-- #main -->
</div><!-- #container -->
<script>
$(document).ready(function() {
$('textarea').bind('blur', function() {
$(this).val(function( i, val ) {
return val;
});
});
});
</script>
So you want to add a div after the textarea
that contains the text from the textarea
?
$('textarea').bind('blur', function() {
var $this = $(this);
$this.after($("<div />").text($this.val()));
});
Did you want to clear the textarea
afterward?
$('textarea').bind('blur', function() {
var $this = $(this);
$this.after($("<div />").text($this.val()));
$this.val('');
});
Also, this markup doesn't appear to be valid
<div id="top-box">Tell us what you're thinking...</p>
Where's your function for saving the text to the database? You can use AJAX to submit the form, and echo json_encode($your_messages);
after your text has been put in the database. From there, in your AJAX success function, you can do whatever you want with that data.