I have a numeric firestore value called 1_star. What i trying to do is to retrieve the 1_star value and show it on my text field. But everytime when I want to retrieve it keep showing me error Uncaught SyntaxError: Numeric separators are not allowed at the end of numeric literal. My html text id is called star1
My code (Javascript):
db.collection("PRODUCTS").doc(pageTitle).get().then((doc) => {
if (doc.exists) {
document.getElementById("star1").value = doc.data().1_star;
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
My firestore value:
My html :
<div class="col-sm-2">
<input
type="number"
class="form-control"
id="star1"
placeholder="1_Star"
name="star1"
required
/>
</div>
I think you are using the type text attribute for your Input field.
You can solve your problem using two methods:
1- Change your input type to number.
2- Convert your data to String using toString(); function if your data type is a number:
db.collection("PRODUCTS").doc(pageTitle).get().then((doc) => {
if (doc.exists) {
document.getElementById("star1").value = doc.data().1_star.toString();
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
Because of you did not share your HTML code I think this might solve your problem.