jquery - I am not able to write javascript array variables values into CSV file in a Given pattern -
i have 3 javascript variables name area, device , problem. want store values of these variables csv file 1 one given in image attached , download sheet on click of download button.both jsp , javascript in same file.i have tried below far.
sample.jsp <form> <input type="button" id="downloadbtn" value="download"> </form> <script type="text/javascript"> var area=["area1","area2"]; var device=[["device1","device2"],["device3","device4"]]; var problem=[[["problem1","problem2"]],[["problem3","problem4"]],[["problem5","problem6"]],[["problem7","problem8"]]]; $("#downloadbtn").click(function() { var resp=confirm("do want download?"); if(resp){ var last = ''; (var = 0; < area.length; i++) { var first = area[i]; (var j = 0; j < first .length; j++) { var second= device[j]; for(var k=0;k<second.length;k++){ var third=problem[k]; var value= third.replace(/"/g, '""'); if (value.search(/("|,|\n)/g) >= 0) value= '"' + value+ '"'; if (k > 0) last += ','; last += value; } } last += '\n'; } var anchor= document.createelement('a'); anchor.setattribute('href', 'data:text/csv;charset=utf-8,' + encodeuricomponent(last )); anchor.setattribute('download', 'sample.csv'); anchor.click(); } }); </script>
please suggest me kind of changes or modification needed desired pattern. how can achieved required in image. comment below kind of clarification on question. suggestion welcome.
Comments
Post a Comment