Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

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?
SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
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
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna 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
Avatar of Bruce Gust

ASKER

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?
ASKER CERTIFIED SOLUTION
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
It was the "tinymce" dynamic that finally got it to work, but thanks for weighing in!