Hi guys,
So I finally got the writer and reader thing working in my iPad app.
However, I want the user to fill out a form and submit the content of
the form and place it in a text file. Then I would read the text file
and parse the information line by line and populate the information. I
can't seem to get the form information and write it to a file though.
Am I missing something?
Here is my code for javascript and HTML
<script type="text/javascript" charset="utf-8" src="phonegap.
0.9.5.1.min.js"></script>
function onLoad() {
document.addEventListener("deviceready", onDeviceReady,
false);
}
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS,
fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("info_account.txt",
{create:true,exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write(
document.forms.info[0].value+"\n");
writer.write(
document.forms.info[1].value+"\n");
writer.write(
document.forms.info[2].value+"\n");
writer.write(
document.forms.info[3].value+"\n");
}
function fail(evt) {
console.log(evt.target.error.code);
}
</script>
<body onload="onLoad()">
<form action="account.html" method="post" name="info" id="info">
<h1>Account Manager</h1>
<table>
<tr>
<td>Practice / Company Name:
<input type="text" name="practicename" id="practicename" value=""></
td>
</tr>
<tr>
<td>First Name:
<input type="text" name="firstname" id="firstname" value=""></td>
</tr>
<tr>
<td>Last Name:
<input type="text" name="lastname" id="lastname" value=""></td>
</tr>
<tr>
<td>Email:
<input type="text" name="email" id="email" value=""></td>
</tr>
<tr>
<td><input type="submit"></td>
</tr>
</table>
</form>
</body>