I have the following code and just cannot find out why doesn't it add the goal to my ForerunnerDB. I did everything as in the example in the ForerunnerDB manual.
Here is my index.html file:
<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<head>
<title>Barebones todo</title>
<script src="./js/dist/fdb-all.min.js" type="text/javascript"></script>
<script src="scrypt.js" type="text/javascript"></script>
</head>
<body>
<form onsubmit="return addGoal();">
Enter goal: <input type="text"id="goalinput">
<input type="submit">
</form>
<button type="button" onclick="retrieve()">Retrieve</button>
<div id="p"></div>
</body>
</html>
Here is my scrypt.js file:
var fdb = new ForerunnerDB();
var db = fdb.db("myDatabaseName");
var goalCollection = db.collection("goal");
function addGoal() {
console.log("addig goal...");
var newgoalname = document.getElementById("goalinput").value;
console.log(newgoalname);
goalCollection.insert({
_id: 3,
name: newgoalname,
order: 99
});
};
function retrieve() {
var findings = goalCollection.find({});
console.log(findings);
//document.getElementById("paragraph").innerHTML = findings;
document.getElementById("p").innerHTML = findings;
}
正如@Luigi Cerone所指出的那样,问题在于
<input type="text"id="goalinput">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.