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?
Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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
Bruce GustPHP 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
hieloCommented:
try "tinymce." (all lowercase) instead of "tinyMCE." - http://archive.tinymce.com/wiki.php/API3:class.tinymce
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
Bruce GustPHP DeveloperAuthor Commented:
It was the "tinymce" dynamic that finally got it to work, but thanks for weighing in!
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
JavaScript

From novice to tech pro — start learning today.