Reputation: 1195
I am trying to grab the value entered into the textarea, but it seems to not be working. I tried it again with instead of and it seems to be working just fine.
Edit: just realized that this has something to do with tinyMCE. Tried it without tinyMCE and it works fine. Any idea why this is?
$('.answers').load(url, function() {
tinyMCE.init({
theme : "advanced",
mode : "textareas",
plugins : "fullpage",
theme_advanced_buttons3_add : "fullpage"
});
$('#submitAnswer').on('click', function(e){
var dataString = $("#addAnswer").val();
alert(dataString);
e.preventDefault();
});
})
Doesn't work with:
<textarea id="addAnswer" name="addAnswer"></textarea>
Works with:
<input id="addAnswer" name="addAnswer"></input>
Upvotes: 0
Views: 174
Reputation: 1195
It's not a textarea any more, so the value property won't work.
This is how you get a reference to the editor, and the text from it:
var text = tinyMCE.get('myeditorid').getContent();
JavaScript to find TinyMCE rich text editor value is null or not
Upvotes: 1
Reputation: 1129
The .val()
atribute works with textArea.
You can check the documentation and this jsFiddle for example.
I think your problem is something related with the timing of the events ( ready and load )
Upvotes: 0
Reputation: 2685
Try:
var dataString = $('#addAnswer').text();
If that doesn't work try:
var dataString = $('#addAnswer').html();
Upvotes: 0