3

I am having a html form when the user submit the form it should save the file as csv and store and when the user again types/submits the form it should get updated in the same csv file.I have used the below code in which it creates a new csv file each time can anyone tell me how to do it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Writing Data to CSV</title>
    <script type="text/javascript">
        function addToCSVFile() {
            var csvData = new Array();  // To collect the names


            // Collecting the names
            csvData[0] = document.getElementById('firstName').value;
            csvData[1] = document.getElementById('middleName').value;
            csvData[2] = document.getElementById('lastName').value;

            window.open('data:text/csv;charset=utf-8,' + csvData.join(','));

            clearData();
            alert("Data Added Successfully");
        }

        function clearData() {
            document.getElementById('firstName').value = "";
            document.getElementById('middleName').value = "";
            document.getElementById('lastName').value = "";
        }
    </script>
</head>
<body>
    <p>
        First Name: <input type="text" id="firstName" />
        <br />
        Middle Name: <input type="text" id="middleName" />
        <br />
        Last Name: <input type="text" id="lastName" />
        <br />
        <input type="button" id="addButton" value="Add to CSV File" onClick="javascript: addToCSVFile()" />
    </p>
</body>

Nidhin Kumar
  • 3,278
  • 9
  • 40
  • 72

0 Answers0