1

Today I'm trying to make a web program that will display div elements containing some <p> and <ul> elements inside a textarea that is initially blank.

Here is what I have so far, but nothing is actually getting outputted to the textarea.

My jsfiddle: http://jsfiddle.net/zHWQD/1/

Here is my function that I think is causing problems...

<script>
myFunction()
{

var subject = document.getElementById("subjectList");
var subjectSelect = subject.options[subject.selectedIndex].text;


var mathDiv = document.getElementById("math");
var paperDiv = document.getElementById("paperediting");
var outputContent = document.getElementById("output");

if (subjectSelect == "Math")
{
outputContent.innerHTML = mathDiv.innerHTML;
} else if (subjectSelect == "Paper Editing")
{
outputContent.innerHTML = paperDiv.innerHTML;
}
}
</script>

The way the code is supposed to work, or the way I thought it should work, is that I have a variable that contains the value from a dropdown menu. (followed the instructions here)

Then, i grab the content of the divs, and save them to variables. (Get content of a DIV using JavaScript)

I then use an if statement to see if the subject selected is equal to either "Math" or "Paper Editing".

Depending on the selection, the content of the output is changed to equal that of the div elements. (How to change the Content of a <textarea> with Javascript)

Any help would be greatly appreciated!

Community
  • 1
  • 1
UvrD
  • 111
  • 3
  • 10

1 Answers1

2

It appears you are forgetting the keyword function before declaring your myFunction().

Because of how jsfiddle wraps your code in window.onload by default, myFunction() is not accessible to use for inline html. You can change this in the top left drop down in jsfiddle swapping onLoad to No wrap - in <head>

I think you likely want to swap your textarea for a div as a textarea will not allow html inside of it.

Ben
  • 872
  • 7
  • 18