how to call ajax code from an external js file

I use this code to create jquery dialog and CKEditor instance

 <input class="boton_fancybox" onclick="createEditor(this);" id="boton_texto" type="button" style="text-decoration:none;" value="Editar el contenido de este campo">

<textarea rows="5" class="campo" cols="90" id="texto" name="texto" style="display:none;"></textarea>

<script type="text/javascript" src="../../contenidos/ckeditor5/ckeditor.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />    
            
<script type="text/javascript">
var editor, html = '';
var config = {};

function createEditor(campo)
{
 var temp = campo.id.split("_");

       if ( editor )
                return;

        $("#div_"+temp[1]).bind('dialogopen', function() //JQ
        {
                editor = CKEDITOR.replace( temp[1],
					{
						height:"600", width:"780",
						toolbar: [
	{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
	{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
	'/',
	{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
	{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote' ] },
	{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
	{ name: 'insert', items: [ 'HorizontalRule', 'SpecialChar', 'Iframe' ] },
	{ name: 'tools', items: [ 'Maximize' ] },
	 { name: 'colors', items: ['TextColor', 'BGColor'] }


	],
		enterMode : CKEDITOR.ENTER_BR,
						shiftEnterMode: CKEDITOR.ENTER_P
					});
        }).bind('dialogclose', function()
        {
                removeEditor();//CK
                $(this).dialog('destroy');
        })
        .dialog({autoOpen: false,
                maxHeight:0.95 * $(window).height(),//1
                width: 800,
                modal: false,
                position: 'top',
                resizable: false,
                autoResize: true }).dialog('open');
}

function removeEditor()
{
        if ( !editor )
                return;

        editor.destroy();
        editor = null;
}
</script>

Open in new window


I tried to use createeditor() and removeeditor() in an external js file to use them in other file but they doesnt works.

I there way to use my code in an external js file????
altariamx2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
Of course there is, just make sure you reference your js file AFTER the ckeditor.js reference.

Also make sure the DOM is ready...
The easiest way is to declare your script last thing before the end of the </body>

This way you're sure all dependencies are loaded and the DOM is ready.
Also like this you don't need to use jquery DOM ready function.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
altariamx2003Author Commented:
So easy!!!!!!!

Mr. Simoes you are a genius!!!!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.