[英]Want to get value from Javascript into HTML form to submit to Firebase database
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. 我完全不喜欢Javascript,而不得不使用来自两个不同教程的代码来构建此输入表单,以帮助我为Andoid应用填充Firebase数据库。 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. 我的一切工作正常,但是如何在脚本中将Url值作为值添加到下面的表单中以提交给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: 这是脚本的正常工作,可以将其加载到Firebase Storage中并返回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. 现在,我希望将该URL值转换为以下形式以提交到Firebase数据库。 Please help what do I put into the "value=" "" field. 请帮助我在“ value =“”字段中输入什么。
<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. 像上面所说的,并不是全部,但是需要这种形式来使我的Android应用程序变得更轻松,在此先感谢您的帮助。
One way of doing that is to use getElementById
as follows: 一种方法是使用getElementById
,如下所示:
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(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.