1
frankblack
WYSIWYG editors and get the content
  • 2009/11/19 10:23

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


I need to get the content of the text typed into the WYSIWYG editor fields with javascript on submission. One should mean that you get it with getElementById
this.addFileParam(file.id'description'document.getElementById("description").value);

but this does not work - the value is always empty.

Instead I have to get it (for tinyMCE) with:
this.addFileParam(file.id'description'tinyMCE.get('description').getContent());


In CKeditor I have to use another code, for Koivi I don't have a clue. So my question is: is there any code I can use for ALL editors?

2
kaotik
Re: WYSIWYG editors and get the content
  • 2009/11/19 11:12

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


All wysiwyg fields are basicly textareas with more options. You could try this with jquery:
switch(n// var n is the editor
{
case 
1:
var 
tst=$("#textarea").val(); //In this case the ID of the wysiwyg textarea is 'textarea'
  
this.addFileParam(file.id'description'tst); //first editor
  
break;
case 
2:
var 
tst=$("#textarea2").val(); //In this case the ID of the wysiwyg textarea is 'textarea'
  
this.addFileParam(file.id'description'tst); //second editor
  
break;
default:
  
//code to be executed if n is different from case 1 and 2
}

In this case I'm doing the switch through javascript, but you could also do it in php.
You can also accomplish this without jquery... you will just need more code

3
frankblack
Re: WYSIWYG editors and get the content
  • 2009/11/19 12:30

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


If I look at your code, I think I don't need a switch if jquery gets the value anyway.

Will test this and report.

Maybe I can be so impertinent and ask you for a solution to auto-collect all form data with jquery. I found code which wasn't working properly in all browsers. You'll get a virtual beer from me if your solution is working.

4
kaotik
Re: WYSIWYG editors and get the content
  • 2009/11/19 12:48

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


Quote:

Maybe I can be so impertinent and ask you for a solution to auto-collect all form data with jquery.

That's actually quite easy with a very handy jquery function called serialize:
<script language="javascript">
$(
document).ready(function() { //Finish loading the entire page before processing any javascript
    
$("#subBut").click(function(event) {
        var 
formContent = $("#form1").serialize(); //get all form fields and properly format them for use with $_GET
        
$("#box").load('myserv.php',formContent);
    });
});
</
script>


<
form name="form1" id="form1" method="post" action="">
<
label>Name
  
<input type="text" name="textfield" id="textfield">
  </
label>
  <
input type="button" name="subBut" id="subBut" value="Submit">
</
form>
<
br />

<
div id="box">Ajax call</div>

Now if your form is being generated dynamically, we need to change the click function to $.live:
<script language="javascript">
$(
document).ready(function() { //Finish loading the entire page before processing any javascript
               
$("#subBut").live("click", function() {    
        var 
formContent = $("#form1").serialize(); //get all form fields and properly format them for use with $_GET
        
$("#box").load('myserv.php',formContent);
    });
});
</
script>


<
form name="form1" id="form1" method="post" action="">
<
label>Name
  
<input type="text" name="textfield" id="textfield">
  </
label>
  <
input type="button" name="subBut" id="subBut" value="Submit">
</
form>
<
br />

<
div id="box">Ajax call</div>


let me know if this helps

Login

Who's Online

194 user(s) are online (127 user(s) are browsing Support Forums)


Members: 0


Guests: 194


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits