Skip to content
Advertisement

add text area on selecting options in dropdown list in java script

JavaScript
JavaScript
JavaScript

UPDATE: I modified codes in your question for better readability @Adam P.

trying to get a text area on selecting multi line text from drop down list SIMAILARLY on selecting single choice add 1 text box below the question and on selecting single choice add 5 text box below the question…

getting error of Cannot read property ‘addEventListener’ of null

Advertisement

Answer

To make textarea visible, you’ll have to do several things:

in JS part, change

JavaScript

to

JavaScript

This change is pretty self-explanatory, you need to define node when you attach eventListener.

In CSS change:

JavaScript

to

JavaScript

You don’t need #one selector, one id selector is enough. Also, when you add a class (.show) to an element that already has id defined, you need to write that class without a space between id name and class name in CSS.

EDIT: You are probably loading your script in <head> tag. This way, script cannot attach eventListener, because DOM element is not available yet. To fix this and remove Cannot read property 'addEventListener' of null error, you need to load your script right before ending of </body>, like this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement