javascript - Get value from console.log and display/print/return in a input field -


how values printed in console.log, , set them values in input field?

here jsfiddle, containing have far - https://jsfiddle.net/ubo1heru/

the code through values put in console.log:

 $("button").click(function() {     var dishkomap = {};     $("select[name='diskho'] > option:selected").each(function() {       var value = this.value;       if (dishkomap[value]) { // if value exists increase 1         dishkomap[value] += 1;       } else {         dishkomap[value] = 1;       }     });     // dishkomap dictionary object won't see in alert.     // open browser console , can see counts corresponding     // each selected option     console.log(dishkomap);    }); 

just create function besides printing in browser console updates value of input field:

 var printtodishkomap = function (data) {     // stringifying data is json     $('input.diskhoval').val(json.stringify(data));     console.log(data);  }   $("button").click(function() {     var dishkomap = {};     $("select[name='diskho'] > option:selected").each(function() {       var value = this.value;       if (dishkomap[value]) { // if value exists increase 1         dishkomap[value] += 1;       } else {         dishkomap[value] = 1;       }     });     // dishkomap dictionary object won't see in alert.     // open browser console , can see counts corresponding     // each selected option     printtodishkomap(dishkomap);   }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -