I have a webpage with text area. I populate this area with a text file of my own, so the user sees the text when they load the page. I want the user to be able to edit the text in this area and they will click 'save'. This will save to MY file, so that the next time someone opens the page they will get the text that the previous user wrote.
I have been looking for quite a while and cannot find what I need. Some things I found said suggest maybe some php (would prefer not). But I have yet to find a source that describes this exact situation.
Here is some of my HTML code:
<div class="emailEditor">
<label for="emailEditBox" class="col-2 col-form-label">Email Editor</label>
<div class="col-10">
<textarea style = "min-height: 300px;" class="form-control" rows="5" id="emailEditBox"></textarea>
</div>
<button id="loadEmail" type="button" class="btn btn-primary" onclick="loadFile()">Load</button>
<button id="saveEmail" type="button" class="btn btn-danger" onclick="saveFile()">Save</button>
<button id="previewEmail" type="button" class="btn btn-success" onclick="previewFile()">Preview</button>
</div>
<div class="emailPreview">
<label class="col-2 col-form-label">Email Preview</label>
<div class="emailOutput">
<!--Preview here (rendered output of the html file)-->
</div>
</div>
Here is some of my Javascript and Jquery:
<script>
function loadFile() {
var reader = new XMLHttpRequest();
reader.open('GET', "EmailTemplate.html", false);
reader.send();
var text = reader.responseText;
document.getElementById("emailEditBox").value = text;
}
function writeFile() {
}
</script>
<script>
$(function previewFile(){
$(".emailOutput").load("EmailTemplate.html");
});
</script>
The load and preview part are working, but I cannot find a way to save the file.