Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

calling textarea on fly in jquery

i have a very classic old HTML javascript editor build in, so i cannot replace it as it is used in whole project,

so here is the code for the editor:

_editor_url = "";             
    var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
    if (win_ie_ver >= 5.5) {
    document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
    document.write(' language="Javascript1.2"></scr' + 'ipt>');
    } else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }

Open in new window


basically this code works as:

<textarea name="abc"></textarea>
<script language="javascript1.2">
editor_generate('abc');
</script>

Now my situation,

I am creating the textarea as such

$(document).ready(function(){
	$('td.edit').click(function(){
	$('.myclass').html($('.myclass textarea').text());
	$('.myclass').removeClass('myclass');
	$(this).addClass('myclass');
	$(this).html('<textarea name="textareabox" id="textareabox" style="width:100%;height:100px;vertical-align:top;">' + $(this).text().trim() + '</textarea><br><span>To [Save] Click enter</span>');
	$('#textareabox').focusEnd();
	}
);

Open in new window


now what exact changes i need to make to load the editor based textarea rather than normal textarea
Avatar of Bruce Cadiz
Bruce Cadiz
Flag of United States of America image

Assuming your editor function is defined and everything works as you described this should work
$(document).ready(function(){
	$('td.edit').click(function(){
	$('.myclass').html($('.myclass textarea').text());
	$('.myclass').removeClass('myclass');
	$(this).addClass('myclass');
	$(this).html('<textarea name="textareabox" id="textareabox" style="width:100%;height:100px;vertical-align:top;">' + $(this).text().trim() + '</textarea><br><span>To [Save] Click enter</span>');
	$('#textareabox').focusEnd();
	editor_generate('textareabox'); //add your editor call here
	}
);

Open in new window

Avatar of Coast Line

ASKER

k,

i am doing it like this

var NewLink = document.createElement('script')
      NewLink.src="/js/editor.js"
      alert(NewLink.src);
      editor_generate('textareabox'); //add your editor call here

but it is giving me an error

ReferenceError: editor_generate is not defined

though i checked the link externally, the editor.js file is there
Since you're using jQuery try this:
$.getScript("/js/editor.js")
.done(function(script, textStatus) {
  console.log( textStatus );
  editor_generate('textareabox');
})
.fail(function(jqxhr, settings, exception) {
  alert("Triggered ajaxError handler." );
});

Open in new window

now another issue, it finds but it keeps reloading the page, happening in firefox and chrome
this gets appended in the url in front

http://wyciwyg://26/
I'd have to see the editor.js code, the "wyciwyg://" (What You See Is What You Get) is most likely is being called by the editor command / code.
ok, here it is, in pastebin

http://pastebin.com/M8wfvesv
ASKER CERTIFIED SOLUTION
Avatar of Bruce Cadiz
Bruce Cadiz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks