How to show particular text in textbox using JQuery? -


i using following code calculate avg value total of 5 different inputs.

var total = p1 + p2 + p3 + p4 + p5; var priority = total / 5; 

i trying show "high", "medium" , "low" inside textbox based on value of variable priority:

i have used code, nothing seems correct, plz help:

if (5 > priority > 4) {     $("#textbox").val('high'); } else if (4 > priority > 2.5) {     $("#textbox").val('medium'); } else if (2.5 > priority > 0) {     $("#textbox").val('low'); } 

you can use .val(function), conditional operator; if priority greater 4 set element value "high"; if priority greater 2.5 set value "medium"; else set value "low"

$("#textbox").val(_, function(val) {   return priority > 4 ? "high" : priority > 2.5 ? "medium" : "low" }); 

Comments