calling textarea on fly in jquery

Gurpreet Singh Randhawa
Gurpreet Singh Randhawa used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bruce CadizQuality Specialist

Commented:
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

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
Bruce CadizQuality Specialist

Commented:
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

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

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/
Bruce CadizQuality Specialist

Commented:
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
Quality Specialist
Commented:
Okay so the issue is that your code (editor.js) uses "document.all" which is a proprietary Microsoft extension to the W3C-standard so it will only work in Internet Explorer. Unless you switch it to document.getElementById or modify the code to use a jQuery selector you're stuck with using IE only.

(document.all)
http://simonwillison.net/2003/Aug/11/documentAll/
http://stackoverflow.com/questions/2408424/document-all-vs-document-getelementbyid
http://msdn.microsoft.com/en-us/library/ie/ms537434%28v=vs.85%29.aspx

jQuery selectors (I'd use this getting anything from id to name)
http://api.jquery.com/category/selectors/

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial