Forum closed. New forum available at http://community.wymeditor.org/

How to reference textarea contents

Support forum for WYMeditor.

How to reference textarea contents

Postby sharkboy on Tue Sep 18, 2007 9:14 pm

First off let me chime in on what a great tool this is. I am using a JS Library that would allow me to add an HTML editor with a single line of code, but it would be all fouled up with font tags, etc. I really appreciate the attention to semantics that wymeditor provides.

I think my question is pretty simple, and please excuse me if it is an obvious one, or if it has been answered in another post (I did search :)).

I am trying to pass the value of the contents of the wymeditor textarea to an alert box when the submit button is clicked.

I know the textarea value can normally be referenced by:

Code: Select all
alert(document.getElementById('myTextarea').value)


but when applied to the wymeditor textarea, the value is null.

What variable or DOM reference can I use to make the alertbox in the code above return the value of the wymeditor textarea?

Thanks very much for your time, and the great tool.
sharkboy
 
Posts: 1
Joined: Tue Sep 18, 2007 9:01 pm

Postby jfh on Thu Sep 20, 2007 7:57 am

You should do something like:
Code: Select all
jQuery(function() {
    jQuery('.wymeditor').wymeditor({
       
        //your options here

        postInit: function(wym) {
            jQuery('#yoursubmitbutton').click( function() {
                alert(wym.xhtml());
            });
        }
    });
});


Note: you can replace 'jQuery' by '$', if you prefer.

It would be a good idea to take a look at jQuery's documentation too, you'll save much time using it, trust me :)
User avatar
jfh
Site Admin
 
Posts: 370
Joined: Sat Sep 23, 2006 8:43 pm
Location: Belgium

Not quite...

Postby eadevel on Thu Sep 27, 2007 12:14 pm

After carefully reading the documentation I had to look at the source code to get the correct answer.

Imagine you had to update two instances with a click of a button, for sending the content with ajax for example.

There's a better way to get the instance without binding it to some function:
var wym = $.wymeditors(index);

If you assume you only have one instance your index will be 0, else you'll have to figure out what's the one you want or iterate them all.

Btw, will this project join the jquery ui library? Or are they doing another rte on their own? Why not join them? ;)
eadevel
 
Posts: 22
Joined: Thu Sep 27, 2007 12:00 pm

Postby paperogiallo on Mon Oct 15, 2007 9:56 am

What variable or DOM reference can I use to make the alertbox in the code above return the value of the wymeditor textarea?


I would like to know the same, I need to retrieve textarea value outside from postInit wymeditor function... :(

Thanks in advance.
paperogiallo
 
Posts: 6
Joined: Tue Oct 09, 2007 1:15 pm

Postby eadevel on Tue Oct 16, 2007 9:43 pm

@paperogiallo
First you get the wym instance:
var wym = $.wymeditors(0);

Then you check the api to see what you can do with it:
http://trac.wymeditor.org/trac/wiki/0.4/API

Basically you can do this:
alert($.wymeditors(0).xhtml());

For testing you can do it using a button:
<button onclick="alert($.wymeditors(0).xhtml());">debug</button>

Hope it helps....
eadevel
 
Posts: 22
Joined: Thu Sep 27, 2007 12:00 pm

Postby paperogiallo on Thu Oct 18, 2007 8:31 am

Yes, it help a lot! Very thanks! :)
paperogiallo
 
Posts: 6
Joined: Tue Oct 09, 2007 1:15 pm


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest