1

I am auto populating text in a text area based on a value selected from a ddl.

Now I can get the text to appear, but I would like that text to be bold.

I have this:

$(document).ready(function () { $('#activityID').change(function () { var selectedActivity = this.options[this.selectedIndex].parentNode.label; var text = "Event Name: \nEvent Location: \nEstimated # of Participants:" var result = text.bold(); if (selectedActivity === "DEMONSTRATIONS") { $('#Summary').val(result); } else if (selectedActivity !== "DEMONSTRATIONS") { $('#Summary').val(""); } }); }); 

In the TextArea it is rendering as:

<B>Event Name: Event Location: Estimated # of Participants:</B> 

Is there any possible way to get this text to render as bold when that specific item is chosen from the DDL?

I have referenced this but this did the same thing as above.

Any help is appreciated.

9
  • 1
    Are you trying to format all text in the text area? Or selectively format it? Commented May 25, 2016 at 18:33
  • 1
    A basic textarea does not support selective formatting. You would need a plugin to make it support rich text. Commented May 25, 2016 at 18:33
  • 1
    NOTE: string.bold() is deprecated and shouldn't be used. See: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented May 25, 2016 at 18:33
  • 1
    In that case you will need some sort of plugin Commented May 25, 2016 at 18:34
  • 1
    Of relevance to the link posted by @Gunther34567 : caniuse.com/#search=contenteditable Commented May 25, 2016 at 18:36

2 Answers 2

1

What he said above, but quote the word bold:

var result = $("<span>").text(text).css({ 'font-weight': 'bold' }); 

Or better yet, apply a CSS class to the field and associate that class with bold in your css files.

var result = $("<span>").text(text).addClass('mybold'); 

And in your css:

span.mybold: { font-weight: bold; } 
Sign up to request clarification or add additional context in comments.

Comments

1

If you want the text to appear bold, you should be changing the CSS properties of the element.

var result = $("<span>").text(text).css({ 'font-weight': 'bold' }); 

This should solve your problem.

1 Comment

Edited my answer. Bold should be a string.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.