0

I want to append font style and type in textarea as per user requirement. I tried but my script is not working...

function run() {
var fontType = document.getElementById("font_type").value;
var fontSize = document.getElementById("font_size").value;

var textArea = document.getElementById("msg");
//alert(fontType+fontSize);

textArea.style.font-size = fontSize ;
textArea.style.font-family = fontType;


}

2 Answers 2

1

Try the following instead:

textArea.style.fontSize = fontSize ;
textArea.style.fontFamily = fontType;

Otherwise your JavaScript is evaluated as:

textArea.style.font - size = fontSize;
textArea.style.font - family = fontType;

... which doesn't make any sense (and so throws a ReferenceError: Invalid left-hand side in assignment).

This conversion (something-something to somethingSomething) is consistent when changing all style properties in JavaScript (border-radius -> borderRadius etc).

Sign up to request clarification or add additional context in comments.

Comments

1

Try:

textArea.style.fontSize = fontSize ;
textArea.style.fontFamily = fontType;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.