i have a textarea in my form
<textarea id="word_count"></textarea>
Cost <input type="text" value=""/>
I used to find the cost based on number of characters the user enters in the textbox. $50 for each 200 characters. result would be like this
cost = $50 for 200 character
$100 for 400 character
$150 for 600 character
I found the number of characters entering in the textbox.
<script>
$("#word_count").on('keyup', function() {
var word_count =$("#word_count").val().replace(/\s/g, "").length;
});
</script>
Prepare a helper json like: var helperJSON ={ 200:'$50', 400: '$100', 600: '$150' }
$("#word_count").on('keyup', function() {
var word_count=$("#word_count").val().replace(/\s/g, "").length;
var cost = helperJSON[word_count];
if(cost){
//do something
}
});
SO when you capture the characters call the helper variable which will give you the costs.
let characterCount = 650;
let price = Math.floor(characterCount / 200) * 50;
console.log (price);
</div>