Skip to content
Advertisement

Textarea typing then show star rating

I have this star rate form and wanted you to start typing in the text area and it will show you the star rate form right away, but if the text area is empty, it will hide.

I discovered the following code:

JavaScript

How can I combine this code into mine? Because it only does that now when I click outside of the text area and then show the stars. Please advise me on this!

JavaScript
JavaScript

Advertisement

Answer

I have taken the liberty of rewriting your code to accomplish what you are trying to do.

Two tips I want to give you:

  1. Decouple the data layer with the presentation layer. You are mixing CSS styles in stylesheets, HTML and JavaScript. You are also having JavaScript as strings in your HTML attributes. This gets confusing quite rapidly! We have gone a long way since HTML4 and the 90’s!

  2. If you use a library, then use it. For example, you are using jQuery, then use it as it should instead of adding event handlers directly to the HTML attributes; jQuery has $(element).on(event, handler), don’t do <div onclick="something(this)"></div>.

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