[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

How to set value of textarea - not working with class

Hi..
I'm trying to set a value of a TEXTAREA.

  <textarea  id="notes" name="notes" class="editor" rows="3" cols="60"></textarea><br/>
                                                  
By doing the follwing

   $(".modal-body #notes").val(' CRAP! ');

Does not work

But


If I remove the class='editor' from the HTML, like this.  It works!!   Any Ideas?

  <textarea  id="notes" name="notes"  rows="3" cols="60"></textarea><br/>
0
JElster
Asked:
JElster
  • 7
  • 6
  • 2
1 Solution
 
Anthony PangilinanDeveloperCommented:
Is there perhaps another bit of JS that is bound to the 'editor' class?  You can try using this (http://sprymedia.co.uk/VisualEvent/) to see if there are multiple functions bound to your element.
0
 
GaryCommented:
Have a live link or can you post the rendered HTML for that code.
The class shouldn't make any difference.
0
 
JElsterAuthor Commented:
Seems this is blocking it
Any ideas?

<script>
        tinymce.init({
              selector:'textarea.editor',
              force_br_newlines : true,
                  force_p_newlines : false,
                  forced_root_block : '', // Needed for 3.x
                  plugins: "code"
              });
</script>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
GaryCommented:
Tinymce doesn't actually use a textarea, it converts it to an editable div
So are you actually using TinyMCE or a textarea?
0
 
Anthony PangilinanDeveloperCommented:
Is that ' tinymce.init()' block executing fine?
0
 
JElsterAuthor Commented:
I think so.. it changes the textarea creates text options. I don't know a thing about it.
0
 
Anthony PangilinanDeveloperCommented:
From what I've read, it looks like after tinymce is initialized, you can only interact with your textarea using tinymce.  Maybe something like one of these would work:

$(tinymce.get('.modal-body #notes')).val(' CRAP! ');

Open in new window


tinymce.get('.modal-body #notes').setContent(' CRAP! ');

Open in new window

0
 
JElsterAuthor Commented:
tinymce is always undefined
??
0
 
Anthony PangilinanDeveloperCommented:
Is the tinyMCE library included before the function call?
0
 
JElsterAuthor Commented:
Yes..
like this
<script src="js/tinymce/tinymce.min.js"></script>
<script>
    tinymce.init({
        selector: 'textarea.editor',
        force_br_newlines: true,
        force_p_newlines: false,
        forced_root_block: '', // Needed for 3.x
        plugins: "code"
    });
</script>
0
 
Anthony PangilinanDeveloperCommented:
It looks like you need the jQuery build of tinyMCE in order to use jQuery calls that reference tinyMCE.  That second suggestion I gave shouldn't have the same problem, but maybe I got something wrong in the syntax.  This page may help http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent.
0
 
JElsterAuthor Commented:
Add the Jquery.. can set the value .. shows it's set in the debugger
but does not display in the textarea
????

      $('.modal-body #notes').val(' this sucks..');
0
 
Anthony PangilinanDeveloperCommented:
tinymce.triggerSave();

Open in new window


or

tinymce.get('.modal-body #notes').save();

Open in new window

0
 
JElsterAuthor Commented:
undefined not a function?
0
 
Anthony PangilinanDeveloperCommented:
Sorry, I may have the syntax wrong again.

http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.save
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now