This question already has answers here:
Get formatted HTML from CKEditor
(12 answers)
Closed 9 years ago.
I'm using CKEditor in my web app, but I don't know how to get html content from it.http://cksource.com/ckeditor
I searched online found one said using getData() method, but there is no getData() method after typing dot after the controler. Can anyone give me a sample code to get html from CKEditor controller? Thank you in advance.
To get htmlData from editor you should use the code snippet bellow:
var htmldata = CKEDITOR.instances.Editor.document.getBody().getHtml();
If this solution won't work, check if you have BBCode plugins installed.
getData() is part of the javascript API.
It seems that you are trying to do it at the server side, so you should check the specific API of whatever wrapper you are using, or just check the value in the form posted data.
Not sure how you're implementing usage of the CKEditor.
If you're replacing a textarea using CKEDITOR.replace( 'NameOfTextarea', this should work:
CKEDITOR.instances.NameOfTextarea.on( 'instanceReady', function( instanceReadyEventObj )
{
var editorInstanceData = CKEDITOR.instances.NameOfTextarea.getData();
alert( editorInstanceData );
});
Replace "NameOfTextarea" with the name of your textarea, it's used to name the editor instance.
It's a good idea to put it inside the "on instanceReady" function so you don't get an undefined error.
Joe
Related
This question already has answers here:
JQuery - $ is not defined
(36 answers)
Closed 11 months ago.
I am using a WordPress website and trying to attach a url to a button using JavaScript. I have written a function to this, My function as follows.
<div class="the_course_button" data-id="3565"><div class="course_button full button">TAKE THIS COURSE</div></div>
jQuery(document).ready(function ($) {
$('#3565').each(function() {
var link = $(this).html();
$(this).contents().wrap('');
});
});
I passed my data-id '#3565' to call the function. Now I am getting nothing
What did I do wrong here?
I appreciate the help thanks so much.
That syntax you are using, is from JQuery, so the error you are getting, is problably because you haven't linked it correctly.
If you want to use JavaScript For making this, you should use document.getElementById("3565")
You will need to change more things if you want to use JavScript, but if you need to use JQuery, you should look this link https://www.w3schools.com/jquery/jquery_get_started.asp
I think you should clarify clearly on which environment you get that error.
Since I see your tag 'wordpress' so I assume you get the error in wordpress.
If so, please read this reference: $ is not a function - jQuery error
Your code should be wrapped like this:
jQuery(document).ready(function ($) {
$('#3565').each(function() {
var link = $(this).html();
$(this).contents().wrap('');
});
});
This question already has answers here:
How to interpolate variables in strings in JavaScript, without concatenation?
(17 answers)
Closed 5 years ago.
As I'm sure you're about to see for yourself, I'm relatively new at coding. I've been struggling to get the png image from json file to show up on my codepen. I've already tried several suggestions I found in my Stackoverflow searches but nothing I've tried seems to work for my situation.
Here's the link to my codepen:
http://codepen.io/mbabaian/pen/MpjbZv
The code I'm trying to use to get the image at this time is:
var currentIcon = wd.current.condition.icon;
// weather icon settings
$("#current-icon").html("<img src='wd.current.condition.icon' alt='weather icon'/> ");
And here's the particular json data where the image is located:
https://api.apixu.com/v1/current.json?key=68629a769f564f9bb6450153170703&q=auto:ip
Please let me know if you need any additional information from me about this. Thanks in advance.
Simply use
$("#current-icon").html("<img src='"+wd.current.condition.icon+"' alt='weather icon'/> ");
Here is your updated codepen
You create currentIcon, use it
$("#current-icon").html('<img src="'+currentIcon+'" alt="weather icon"/>');
This is probably a stupid mistake that i have made; i am still new to web development so be nice please :)
Here i create the object
var crs0 = {ID:1, TITLE:"test", DESC:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",ER:"a",LENGTH:"a", FEE:"a"};
Here i use an onclick event to call a function & pass the object as a parameter
<div class = "btnDC" onclick="display(crs0)">test</div>
Here is the function that i use to replace data in some textarea's & text inputs with properties from the object.
function display(crs)
{
document.getElementById("ttl").value=crs.TITLE;
document.getElementById("dsc").value=crs.DESC;
document.getElementById("er").value=crs.ER;
document.getElementById("lng").value=crs.LENGTH;
document.getElementById("fees").value=crs.FEE;
document.getElementById("ID").value=crs.ID;
}
The onclick does nothing & i have no idea why. (Other javascript on the page does work so i haven't missed a semi-colon :D )
[Update 1]
All of the data is pulled from a database the code above is copied from the page it produces; i have done a few tweaks & i can get it to produce an alert box for the display function however if i try & make it show any data of the object within that alert box it doesn't display anything (i hate not having a debugger), which suggests that the object isn't being passed.
Here is the PHP code i use to create the onclick
echo '<div class = "btnDC" onclick="display(crs'.$n.')">'.$inf['TITLE'][$n].'</div>
Could that be the issue?
it produces this line of code
<div class = "btnDC" onclick="display(crs0)">test</div>
As mentioned the code i have shown works (thanks juvian);
I generated this code from php & although the javascript generated was correct there was a problem with some of the php, i didn't find the exact problem but i have re-written most of the php & now it works.
As mentioned the code i have shown works (thanks juvian); I generated this code from php & although the javascript generated was correct there was a problem with some of the php, i didn't find the exact problem but i have re-written most of the php & now it works.
I have a college project in which i am using ace editor on a webpage. https://github.com/ajaxorg/ace
Ace editor customizes tag to look like a editor. I can extract its value usign jquery .val() function or editor API but the source code looses its syntax.
For example if the code is :
System.out.printls("Enter number");
int value = ScannnerObj.nextInt();
The extracted values looks like :
System.out.printls("Enter number");int value = ScannnerObj.nextInt(); //All in one line
I have to extract this value from editor and save it in database I am using Django for it.
Later I also want to retrieve it in such that the Program Syntax is not altered.
Can anyone tell my correct way to achieve this. I am missing some link in here.
Thanx in advance :)
Ok guys I found the solution for it :) use the following code to render ace editor
editor = ace.edit("editor");
not
var editor = ace.edit("editor"); //(not to write var)
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
JavaScript query string
...Riight. I found the answer to my problem. I'd forgot to add '' around some jsp scriplet tags in my popup window code. Because of this values that should've been strings weren't handled properly.
I'll flag this question for moderator attention. The only thing one can learn from this question is to pay attention when using jsp scriptlets.
I want to open a popup from my .js code using window.open(). I have a couple of parameters that I need to pass to this popup. I'm surprised it's not as simple as I would've thought, I've tried searching for answers but all I found were solutions that were quite complicated - I hope there's a simple answer.
There's a multitude of ways I've tried doing this, but this is how I think it should work..
window.open('../common/MapPopup.jsp?current='+currentPosition+'&areas='+sAreas, 'mywindow', 'width=600,height=450,scrollbars=yes');
I'm at a total loss. Could it be that window.open just doesn't work in this situation?
edit: Currently my page behaves like this. The user presses a form button, which launches a query into our database. From this data a DataTables table is created. As the DataTable is being initialised, so is a piece of jQuery code. I'm using jQuery to open a popup when the user clicks on a row in the DataTables table.
renderReport: function(response){
$('#requestDataContainer').html(response);
oTable = $('#dataTable').dataTable({
"bPaginate": true,
--snip-- //DataTables init
});
var sProcedures = new Array();
var sAreas = new Array();
var sCurrentPosition = null;
$('#dataTable tr').click(function(){
var sCurrentPosition = oTable.fnGetData(this,9);
if(sCurrentPosition!=null){
$('#dataTable').find('tr').each(function(){
var foo = oTable.fnGetData(this);
if(foo!=null){
if(foo[8]!='null')
sAreas.push(foo[8]);
if(foo[7]!='null')
sProcedures.push(foo[7]);
}
});
}
window.open('../common/reportMapPopup.jsp?procedures='+sProcedures+'&areas='+sAreas+'¤t='+sCurrentPosition, 'reportMap', 'width=600,height=450,scrollbars=yes');
});
},
I have to admit, I'm quite newbish when it comes to webcode. I'm kind of learning on the go, so the terminology might be new to me and I could be doing things in a really silly way. It could be that I found the answer when I was looking for it on the web, but just didn't realise it.
If the query string in your url gets passed to the window you should be able to access those parameters from the window using JS using the location object(http://www.w3schools.com/jsref/obj_location.asp)
If you have access to the actual page - can you not retieve the params using jsp?