<html> <head> <script> var a1 = { accNo:101, name:"Sumit", balance:45000} var a2 = { accNo:102, name:"Megha", balance:123500} var accArray = [a1, a2] function addAccount() { var accObj = { } accObj.accNo = parseInt(document.getElementById("input1").value) accObj.name = document.getElementById("input2").value accObj.balance = parseFloat(document.getElementById("input3").value) accArray.push(accObj) document.getElementById("input1").value="" document.getElementById("input2").value="" document.getElementById("input3").value="" display() } function deleteData(accNo) { alert("deleted: "+accNo) for(i=0;i<accArray.length;i++) { var accObj = accArray[i] if(accNo == accObj.accNo){ accArray.splice(i,1) // display() break } } } function display() { let divOutput = document.getElementById("output") divOutput.innerHTML="" for(acc of accArray) { var str = acc.accNo +","+acc.name +","+ acc.balance+" " var delButton = "<input type='button' value='Delete' onclick='deleteData(" + acc.accNo+")' />" str=str+delButton + "<br>" divOutput.innerHTML = divOutput.innerHTML+str } } </script> </head> <body> <input type="button" value="Display" onclick="display()" /><br> <input type="text" placeholder="Acc Number" id="input1" /><br> <input type="text" placeholder="Name" id="input2" /><br> <input type="text" placeholder="Balance" id="input3" /><br> <input type="button" value="Add" onclick="addAccount()" /><br> <br> <div id="output" style="background-color: greenyellow;"> accounts </div> </body> </html>
Office no.- 401,Shekhar Central Building ,Palasiya, Pin-code:452001, Indore
contact@codebetter.in
+91 88230 75444, +91 99939 28766