i made this code with the help of friends. Now i was trying to add functionality as mentioned as under. But i was not able to get success.
here is the fiddle.
Fiddle: http://jsfiddle.net/FLgsq/
jquery code:
$(document).ready(function () {
$('#word_count').wordCount();
});
jQuery.fn.wordCount = function (params) {
var p = {
counterElement: "display_count"
};
var total_words;
if (params) {
jQuery.extend(p, params);
}
//for each keypress function on text areas
this.keypress(function () {
total_words = this.value.split(/[\s\.\?]+/).length;
jQuery('#' + p.counterElement).html(total_words);
});
};
$(document).ready(function () {
$('input[name=rdOptin]').click(function () {
var selected = $(this).val();
var var0 = 0.3;
var var1 = 20;
var var2 = var1 * 3.9 / 100;
var var3 = 20;
var var4 = (var1 + var3) * 3.9 / 100;
if (selected == 'norm')
var total = var0 + var1 + var2;
else
var total = var0 + var1 + var3 + var4;
$("#calc_value").html("<span style='color: red;'>Numbers</span> <span style='color: green;'>" + total.toFixed(2) + "</span>");
});
});
what i was trying to achieve is, how can i do that if the number of words in the textfield (which is already counted by the function "jQuery.fn.wordCount") increase more than 13 the output of variable "total" change accordingly with the already existing functionailty (i.e. it is also monitoring radio "rdOptin" and doing calculation based on that). Rather it just adds +5 or it the numbers is between 13-18 it shall add 5 to the output of portion "Calculated Value:", then if 18-23 adds 10, then 24-28 adds 15 and so on or 6 iterations can be taken.
how can it be done guys?