How can I clear the contents of a textarea with this function?

Here's my function:

function spanishAlertYes(check)
	{
		//at this point, if the user clicks on this option, their changing their minds. If they said they needed a Spanish option, this will be checked by default. 
		//if they do change their minds, then everything they might've entered as far as "employee / spouse" values will be zeroed out and they'll be starting all over again as if they just completed their basic aesthetics
		if(check.checked)
		{
			$('.submit_class').hide(100);
			$('#submit_explanation').html("");
			$('#emp_spouse_no').prop('checked', false);
			$('#emp_spouse_yes').prop('checked', false);
			$('.employer_options').show(100);
			$(".employee_spouse_name").hide(100);
			$('#homepage_text_one').html('will I get this to work');
		}
	}

Open in new window


Everything works just fine with the exception of the fact that I want to clear out whatever might be in the "homepage_text_one" field and replace it with "will I get this to work."

What's happening is that the user is backtracking. They've put a value in the "homepage_text_one" textarea, but now they're changing their minds as is evidenced by them having clicked on the radio button that triggers the above function.

What am I missing?
brucegustPHP DeveloperAsked:
Who is Participating?
 
hieloCommented:
try "tinymce." (all lowercase) instead of "tinyMCE." - http://archive.tinymce.com/wiki.php/API3:class.tinymce
0
 
zephyr_hex (Megan)DeveloperCommented:
Works fine for me:  https://jsfiddle.net/zephyr_hex/wmy1Lv04/

Are you sure you have your code wrapped in document ready ?
And have you verified the id attribute on your textarea?
0
 
hieloCommented:
If #homepage_text_one is in fact a textarea, then you need to change its value (not its innerHTML):
$('#homepage_text_one').val('will I get this to work');

Open in new window

0
 
brucegustPHP DeveloperAuthor Commented:
Guys, I just realized why I'm running into difficulties.

I'm using a tinyMCE text editor. The code that clears the content from the text area is going to be:

tinyMCE.getInstanceById('homepage_text_1').setContent(' ');

See http://www.prettyscripts.com/free/tinymce-clear-field/ for reference.

Thing is, when I do that, I get an error:

employer_insert.php:404 Uncaught TypeError: tinyMCE.getInstanceById is not a function
    at spanishAlertYes (employer_insert.php:404)
    at HTMLInputElement.onchange (employer_insert.php:292)

After googling for something that might explain that error, I get some answers saying that I don't have the tinyMCE library loaded, but I do as is evidenced by the fact that you can see the texteditor.

My code looks like this:

	function spanishAlertYes(check)
	{
		if(check.checked)
		{
			$('.submit_class').show(100);
			$('.employer_options').hide(100);
			$('.employee_spouse_name').hide(100);
			//zero-ing out any previously checked values should the user backtrack and change their mind about a Spanish version
			$('#emp_spouse_yes_no').prop("checked", false);
			$('#emp_spouse_no').prop("checked", false);
			tinyMCE.getInstanceById('homepage_text_1').setContent(' ');
			$('#homepage_text_2').val(' ');
			$('#submit_explanation').html("<br><div style=\"width:95%; margin:auto; text-align:center; border:1px solid #cccccc; border-radius:10pt; padding:10px;\">When you click on \"Submit,\" you will be creating the basic aesthetics of your user's landing page. From here, you'll be directed to another interface where you'll being creating the user's Landing Page experience in Spanish.</div>");
		}
	}

Open in new window


Everything works except the "tinyMCE.getInstanceById('homepage_text_1').setContent(' ');" line.

Any ideas?
0
 
brucegustPHP DeveloperAuthor Commented:
It was the "tinymce" dynamic that finally got it to work, but thanks for weighing in!
0
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.

All Courses

From novice to tech pro — start learning today.