Advertisement
gsmashik

one page edit add

Sep 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
  2. <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
  3. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  4. <!------ Include the above in your HEAD tag ---------->
  5.  
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
  10. </head>
  11. <body>
  12. <input type="text" id="one" placeholder="name">
  13. <input type="number" id="two" placeholder="age">
  14. <input type="text" id="three" placeholder="Address">
  15. <button onclick="add()">Add</button>
  16. <button onclick="update()">Update</button>
  17.  
  18. <table class="table table-bordered">
  19. <thead>
  20. <th>Sl.No</th>
  21. <th>Name</th>
  22. <th>Age</th>
  23. <th>Address</th>
  24. <th>Action</th>
  25. </thead>
  26. <tbody id="data">
  27. </tbody>
  28.  
  29. </table>
  30.  
  31. <script>
  32. var newone=[]
  33. var newtwo=[]
  34. var newthree=[]
  35.  
  36. function add(){
  37.  
  38. var one=document.getElementById('one').value
  39. var two=document.getElementById('two').value
  40. var three=document.getElementById('three').value
  41. newone.push(one);
  42. newtwo.push(two);
  43. newthree.push(three);
  44. listshow();
  45. }
  46.  
  47. function listshow(){
  48. var list=""
  49. for(var i=0;i<newone.length;i++){
  50. list+= "<tr><td>"+(i+1)+"</td>"+"<td>"+newone[i]+"</td>"+"<td>"+newtwo[i]+"</td>"+"<td>"+newthree[i]+"</td>"+"<td>"+"<button onclick='edt("+i+")'>Edit</button><button onclick='del("+i+")'>Delete</button>"+"</td></tr>"
  51.  
  52. }
  53. document.getElementById('data').innerHTML=list
  54.  
  55. }
  56.  
  57. var load=""
  58. function edt(edit){
  59. load=edit
  60. document.getElementById('one').value=newone[edit]
  61. document.getElementById('two').value=newtwo[edit]
  62. document.getElementById('three').value=newthree[edit]
  63.  
  64. }
  65.  
  66. function update(){
  67. newone[load]=document.getElementById('one').value
  68. newtwo[load]=document.getElementById('two').value
  69. newthree[load]=document.getElementById('three').value
  70. listshow();
  71.  
  72. }
  73.  
  74. function del(dok){
  75. newone.splice(dok,1)
  76. newtwo.splice(dok,1)
  77. newthree.splice(dok,1)
  78. listshow();
  79. }
  80.  
  81.  
  82.  
  83. </script>
  84.  
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement