Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2007-01-17 14:57:54

suzannesmith
New member
Registered: 2007-01-16
Posts: 9

Xinha and AJAX - turning Xinha textarea into a regular textarea

Hi,
When my page first loads, the textarea that I've got the Xinha code attached to shows up fine.  When I use an AJAX function to load the textarea, it turns into a regular textarea. 

Is there a way to re-initialize (?) the textarea as a Xinha textarea without reloading the screen?

Thank you,
Suzanne

Offline

#2 2007-01-17 19:33:44

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: Xinha and AJAX - turning Xinha textarea into a regular textarea

If I get you right you want to load new contents in the editor. If that's the case, you don't have to insert a whole new textarea in the page. Use the Xinha method setHTML() instead.

var newHtml = "some HTML";

xinha_editors.myTextArea.setHTML(newHtml);

Offline

#3 2007-01-19 11:19:18

suzannesmith
New member
Registered: 2007-01-16
Posts: 9

Re: Xinha and AJAX - turning Xinha textarea into a regular textarea

Worked like a charm!  Thanks

Offline

#4 2008-01-15 23:23:01

forkie
New member
Registered: 2008-01-15
Posts: 1

Re: Xinha and AJAX - turning Xinha textarea into a regular textarea

Hi all,

I tried this and it didn't work. I have a basic HTML file that contains the following within the <head> section
<head>
<script src="myajaxfunctions.js" type="text/javascript"></script> 
<script type="text/javascript">
    _editor_url  = "../"  // (preferably absolute) URL (including trailing slash) where Xinha is installed
    _editor_lang = "en";      // And the language we need to use in the editor.
    _editor_skin = "silva";   // If you want use skin, add the name here
  </script>
  <script type="text/javascript" src="../XinhaCore.js"></script>
  <script type="text/javascript" src="XinhaConfig.js"></script>
</head>

and a <DIV id="main">editor will be here</DIV> within the <body>, then I have an AJAX function that I pass the URL I want to retrieve and the DIV I want to replace and it will put the contents returned from the URL directly into the DIV. Basically like this

<span onclick="myAJAXFunction('basic.php', 'main');">Click here to load editor</span>

I have the following PHP file that returns my form
code:
<?

echo '<form action="">
<div>
<textarea id="myTextArea" name="myTextArea" rows="10" cols="50" style="width: 100%">other stuff</textarea>
</div>
</form>
<script type="text/javascript">

var newHtml = "some HTML";

xinha_editors.myTextArea.setHTML(newHtml);

</script>';

?>

I know it is loading the form correctly because I am getting standard <textarea> but the Xinha editor is not loading.

Can someone please tell me what I am doing wrong! sad

Many thanks,
Forkie

Offline

#5 2008-01-24 00:28:10

beanstalk
Xinha Community Member
Registered: 2007-02-06
Posts: 13

Re: Xinha and AJAX - turning Xinha textarea into a regular textarea

i've struggled with this myself.  i hid the textarea.  then i put the initialization code (stuff in xinhaconfig.js) into the javascript function that shows the textarea.  i also had to set a variable after i had been there once.  otherwise, each time i show the textarea, it adds another editor.

Offline

#6 2008-07-05 18:13:35

channis
New member
Registered: 2008-07-05
Posts: 3

Re: Xinha and AJAX - turning Xinha textarea into a regular textarea

Yeah, I'm trying to do the same and i believe I'm not the only one with this issue...gonna keep trying and if I got the answer, i'll let you know. In fact, i started a new post about the subject called "Xinha, Ajax, httpRequest object and innerHtml property".
Please keep in touch

Channis

Offline

#7 2008-07-06 06:49:31

MyLocalFOCUS.com
Xinha Community Member
Registered: 2007-02-17
Posts: 31

Re: Xinha and AJAX - turning Xinha textarea into a regular textarea

This is a response to forkies code...

When I have tried doing javascript in an AJAX response, I have never been able to get it to work... though I didn't look too deep into it. Does the textarea with the sample JS actually show 'some HTML'?

If so (and the javascript is actually running), then the only thing I can think of is that you need to initialise the textarea just before you setHTML.


      xinha_editors = xinha_editors ? xinha_editors :
      [
        'myTextArea'
      ];

After this, I think you need to somehow re-call the myconfig and xinhacore.js files. Perhaps something like this altogethor shoudl be returned...



<form action="">
<div>
<textarea id="myTextArea" name="myTextArea" rows="10" cols="50" style="width: 100%">other stuff</textarea>
</div>
</form>
<script type="text/javascript">

      xinha_editors = xinha_editors ? xinha_editors :
      [
        'myTextArea'
      ];


var newHtml = "some HTML";

xinha_editors.myTextArea.setHTML(newHtml);

</script>

<script type="text/javascript" src="/PathToEditor/editor/XinhaCore.js"></script>
<script type="text/javascript" src="/PathToEditor/editor/myconfig.js"></script>

(You may need to adjust the positioning of the two tags above... I would expect AFTER the declaration of myTextArea but before the var newHTML. Also, it is assumed that myconfig.js does NOT have the declaration of the textarea. (I also think that the XinhaCore.js can be loaded at the top of the page rather than after the editor)).

Hope this helps.

Offline

Board footer

Powered by FluxBB