calculate textarea data using JavaScript -


i have text area ,and have default value in it

 <textarea rows="10" cols="50" id="textarea">    john: 2  jane: 3  john: 4  jane: 5  </textarea> 

i want find total of john or jane when button clicked.also same calculation when new value entered user .

*needs in javascript

i appreciate suggestions or sample code

very strange way enter kind of data!

anyway may try (also strange:-):

var result = {}; document.getelementbyid('textarea').value.match(/\w+:\s+\d+/g) .foreach(function(element) {     var data = element.match(/(\w+):\s+(\d+)/),         name = data[1],         value = data[2];     if (typeof result[name] == 'undefined') {         result[name] = 0;     }     result[name] += +value; }); console.log(result); 

fiddle


Comments