Skip to content
Advertisement

How to display different output based on a text box input using Javascript?

I am creating a grading system with a perfect score of 100. The total is automatically calculated depending the score provided and it is read only. Now, I want to show another text box a short remarks based on the total without the submit button. For example, if the grade is 90 and below, the remarks should automatically be set to ‘Very Good’ and if less than or equal to 80, the remarks will be “Good”.

JavaScript
JavaScript

I tried to use different if/else statement with JavaScript but it is not picking up the elseif function.

Advertisement

Answer

Your code needed a lot of cleaning, there were for example 2 <th> nested tags I don’t know why, here is a working flexible example, just insert the number and press calculate

JavaScript
JavaScript

Also there were a lot of javascript errors, as noted by @Snel23

If you want to remove the Calculate button and make the feedback show whenever you insert something in the input field, just do this:

  • Remove the <button> tag
  • Add your <input onkeyup="calculate()"> to the <input> tag

Here is a snippet for that:

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