Reputation: 131
I'm not at all into Javascript but had to build this input form using code from two different tutorials to help me populate my Firebase database for my Andoid app. I got Everything working good, but how do I get the Url value in the script as a value into the form below to submit to Firebase. As I said, everything is working but I just cant get that value into the form to submit.
This is the script working fine, loading into Firebase Storage and returning the URL:
function() {
var starsRef = storageRef.child('images/'+ file.name);
starsRef.getDownloadURL().then(function(url) {
document.querySelector('#preview').src = url;
var t=document.querySelector('p')
t.innerHTML = '<b>Firebase Storage URL: </b>' + url
}).catch(function(error) {
console.log('Error Download File');
});
});
}
</script>
Now I want that url value into the below form to submit to my Firebase Database. Please help what do I put into the "value=" "" field.
<p>
<input type="hidden" name="image" id="image" value=url>
<label>Name</label>
<input type="text" name="name" id="name" required>
</p>
<p>
<button type="submit">Submit</button>
</p>
</form>
Like mention above not at all into this, but need this form to make life easier with my Android app, thank you well in advance for help.
Upvotes: 0
Views: 292
Reputation: 83093
One way of doing that is to use getElementById
as follows:
var starsRef = storageRef.child('images/' + file.name);
starsRef.getDownloadURL()
.then(function (url) {
document.getElementById("image").value = url;
document.querySelector('#preview').src = url;
var t = document.querySelector('p')
t.innerHTML = '<b>Firebase Storage URL: </b>' + url
})
.catch(...)
Upvotes: 1