Announcement

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

#1 2007-04-13 09:46:03

cedric57
New member
Registered: 2007-04-13
Posts: 5

How to modify a Xinha textarea's value with Javascript ?

Hello,

I'm sorry for my poor english, i'm french. So this is my problem:
I want to modify the color of a Xinha textarea's value with a script directly from a listbox. Here is my code  :

// My script
<script language="javascript">
    function change_risk(valeur) {
      var reg = new RegExp("<font color=(\"|\')#[0-9a-fA-F]{6}(\"|\')>","gi");
      
      document.form.vulnerability_name.value = document.form.vulnerability_name.value.replace(reg,"<font color='" + valeur + "'>");
    }  
</script>

// My list
<select onChange="change_risk(document.form.risk.options[document.form.risk.selectedIndex].value)" name="risk">
  <option value="#ff0000">High</option>
  <option value="#00ff00">Medium</option>
  <option value="#0000ff">Low</option>
</select>

// My textarea
<textarea id="vulnerability_name" name="vulnerability_name" rows="3" cols="100">
    <center><big><font color="#000000"><b>Bla bla bla bla</b></font></big></center>
</textarea>

I found that it works fine if I first convert my Xinha's textarea in HTML (with the HTML button in the Xhina's toolbar) before I make the change in the listbox. If I don't do that, the textarea's value doesn't change... but I want that it works anytime.
What can I do to resolve this ?

Maybe I could modify my javascript to automatically convert the value in HTML, apply the change and convert it in Xhina's format (without clicking on any button of the toolbar), but i don't know how. I need help.

Thank you for any idea wink

Cedric

Last edited by cedric57 (2007-04-16 11:14:49)

Offline

#2 2007-04-16 05:02:27

cedric57
New member
Registered: 2007-04-13
Posts: 5

Re: How to modify a Xinha textarea's value with Javascript ?

No idea ?
So I suppose it's not possible...

Thank you

Cedric

Offline

#3 2007-04-16 10:30:19

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

Re: How to modify a Xinha textarea's value with Javascript ?

var html = xinha_editors.yourEditor.outwardHtml(xinha_editors.yourEditor.getHTML());
// do something with it 
xinha_editors.yourEditor.setHTML(xinha_editors.yourEditor.inwardHtml(html))

Offline

#4 2007-04-16 10:46:49

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

Re: How to modify a Xinha textarea's value with Javascript ?

var html = xinha_editors.yourEditor.outwardHtml(xinha_editors.yourEditor.getHTML());
// do something with it 
xinha_editors.yourEditor.setHTML(xinha_editors.yourEditor.inwardHtml(html))

Offline

#5 2007-04-16 11:15:55

cedric57
New member
Registered: 2007-04-13
Posts: 5

Re: How to modify a Xinha textarea's value with Javascript ?

Ok I will look at this wink

Thanks for your help

Offline

#6 2007-04-16 11:36:08

cedric57
New member
Registered: 2007-04-13
Posts: 5

Re: How to modify a Xinha textarea's value with Javascript ?

I did :

<script language="javascript">
    function change_risk(valeur) {
      var reg = new RegExp("<font color=(\"|\')#[0-9a-fA-F]{6}(\"|\')>","gi");
      
      var html = xinha_editors.vulnerability_name.outwardHtml(xinha_editors.vulnerability_name.getHTML());
      xinha_editors.vulnerability_name.setHTML(xinha_editors.vulnerability_name.inwardHtml(html));
      
      document.form.vulnerability_name.value = document.form.vulnerability_name.value.replace(reg,"<font color='" + valeur + "'>");
    }  
</script>

But it doesn't change anything. I don't understand what i have to do with your code... I thought that it permits to convert the value in HTML and then permits to change its color. But I'm not sure how to use it.

Can you give me more details about these properties ?

Cedric

Offline

#7 2007-04-16 12:45:51

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

Re: How to modify a Xinha textarea's value with Javascript ?

<script language="javascript">
    function change_risk(valeur) {
      var reg = new RegExp("<font color=(\"|\')#[0-9a-fA-F]{6}(\"|\')>","gi");
    
     // the below retrieves the Xinha content and stores it in the variable html; now you can do things with it
      var html = xinha_editors.vulnerability_name.outwardHtml(xinha_editors.vulnerability_name.getHTML());
      // change it 
      html = html.replace(reg,"<font color='" + valeur + "'>");
      
      // then put it back in the editor
      xinha_editors.vulnerability_name.setHTML(xinha_editors.vulnerability_name.inwardHtml(html));
      
      // this does nothing, because the editor area is independent from the textarea
      //document.form.vulnerability_name.value = document.form.vulnerability_name.value.replace(reg,"<font color='" + valeur + "'>");
    }  
</script>

Offline

#8 2007-04-19 09:55:23

cedric57
New member
Registered: 2007-04-13
Posts: 5

Re: How to modify a Xinha textarea's value with Javascript ?

Great ! It works !!!

Thank you very much and very good job for your HTML editor (probably the best i've found) wink

See U

Offline

Board footer

Powered by FluxBB