Get DotNetNuke Text Editor HTML Value with JQUERY / Javascript - javascript

I'd like to get DNN Text Editor's value from client side jQuery or javascript.
I could retrieve the element by id but I'm nowhere close to get the value / content of the text editor. Can anyone show me a way or an alternative way to achieve this?
With the help of this link, I could only manage to get the id as below but when I tried to console out, it's 'undefined'.
var txt = $('#<%= ResourceText.ClientID %>_ResourceText');

Try the following: $('#<%= ResourceText.ClientID %>_ResourceText').val()

Related

Apply code highlighter to Textarea

I have a textarea in my website contains PHP code.
I want to make the users able to Modify the code and then Run it.
So, I have made a textarea called modifyCode:
<textarea id="modifyCode"></textarea>
So far I have managed to run the PHP code which is written in the textarea.
BUT, I really like to apply code highlighter to my text box. With this regard, I have tried a couple of ways:
I have tried "highlight.js" --> https://highlightjs.org/
I have tried "codemirror" --> https://codemirror.net/
Not only I can't get my PHP code to be highlighted, but also it can't be running anymore.
I need to mention that the same method is working fine to highlight XML code, but it won't run too!
As far as I understood, when we apply these code highlighters, the textarea will not act like a textarea anymore. So, is there anyway that I can highlight my PHP code and then run it?
A way to encounter with this issue is to make an middle DIV called modifyCodeDiv:
<div id="modifyCodeDiv" contenteditable="true"></div>
modifyCodeDiv is getting the value of modifyCode textarea:
document.getElementById("modifyCodeDiv").innerHTML =
document.getElementById("modifyCode").value;
So, users can modify the code in the div modifyCodeDiv.
To execute the code, you need to send the value of modifyCodeDiv to modifyCode. As div does not have value attribute, you need to do:
var my_element = document.getElementById('modifyCodeDiv');
var my_str = my_element.innerText || my_element.textContent;
document.getElementById("modifyCode").value = my_str;
Furthermore, you can apply highlight.js to your div modifyCodeDiv.

getting values from javascript to apex code

I need to get a value from a javascript variable into a text field in a visualforce page.
I got it using a command button.But I was wondering if there is any other way of getting it,cz i dun want an onclick event.
Thanks in advance
I can't tell by your comment what event you're listening for, but assuming you know what that will be, just use document.getElementById() or a selector in jQuery to get the input field. If you are using Apex:inputField, define the id attribute with something like 'theField'. When the page is rendered, Salesforce should give an id attribute like 'j_id0:j_id1:theField' to the real tag, but this can and probably will be different every time the page is viewed. That means you're going to need to select the input by a substring. Here's some sample code using jQuery (apologies to any jq gurus out there if it's inefficient-- feel free to improve).
<apex:page>
<apex:includeScript value="{!$Resource.jquery_1_6_1}"/>
<script>
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('input[id*="theInput"]').val('Hello World');
});
</script>
<apex:form >
<apex:inputText value="{!phonenum}" id="theInput"/>
</apex:form>
</apex:page>

get tinyEditor value in javascript

i am using tinyEditor as my text editor, but i donno how to get a tinyEditor textarea's value in javascript.
when i user document.getElementById('texteditor').value; it gives me null. nothing.
anyone know how to fix this problem?
this is the site for tinyEditor
Try this (editor is the instance):
editor.post();
var textAreaHtml = editor.t.value;
Well, the standard way is:
tinyMCE.get('element-ID').getContent();
which element-ID is the id of the textarea used for tinyMCE.
editor.i.contentWindow.document.body.innerHTML
this will return value of editor, but this is hack, this is not valid access, as I can see method for getting content doesn't exists.
so "editor" is name of your editor.

jQuery serialize problem

On my website I have a CKEDITOR to publish content. I have build an automatic save function when you switch pages that looks like this:
var oEditor = CKEDITOR.instances.text;
var content = oEditor.getData();
$('#form #text').html(content);
$.post("news/save/" + id + "/" + page, $("#form").serialize());
This gets the current content of the editor, places it in the textarea (it did not always do that automatically apparently). Then serializes the entire form and posts it to my website's save page.
This is works except for when I put youtube code inside the editor. Printing out the following works without any problems (after the content was set):
alert($('#form #text').html());
This would just prints the actual content with the youtube code. But when the .serialize() functions is called the content gets empty.
alert($('#form #text').serialize());
This would just print: "text=%0A".
Can anybody help me fix this problem or suggest another way to post the form's content to the save page?
Thank you.
Is #text is a textarea? if it is then you should probably using val() method to set the value instead of html(), because val() should be used to set/get form element's value.
You should call editor's synchronize procedure, that synchronizes editor contents with the value of the textarea.
After that, the value will be available for serialization as well.

JavaScript to find TinyMCE rich text editor value is null or not

I use the TinyMCE textarea in one of my web applications.
How to check the TinyMCE textarea's value is null or not using JavaScript?
document.getElementById("myeditorid").value didn't help me.
It's not a textarea any more, so the value property won't work.
This is how you get a reference to the editor, and the text from it:
var text = tinyMCE.get('myeditorid').getContent();
var text = tinyMCE.get('createSurvey:thankyouMsg_ifr').getContent();
here the predefined id was "thankyouMsg"..After the tinyMCe,its id changed to this.I try to get the value in this way but it is not working saying tinyMCE.get('createSurvey:thankyouMsg_ifr') is undefined

Categories

Resources