简体   繁体   English

希望从Javascript转换为HTML表单以提交到Firebase数据库的价值

[英]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.

相关问题 我想在提交之前使用javascript从表单中获取价值 - i want to get value from the form using javascript before submit 如何从选择表单中获取选项的值并将其提交到Firebase - how to get the value of options from select form and submit it to firebase 提交HTML表单并获取无JavaScript或jquery的单选按钮值 - Submit HTML form and get radio button value without javascript or jquery html / javascript:防止 <input> 表单提交时的清算价值 - html / javascript: Prevent <input> value from clearing on form submit 在html表单提交后保留javascript的innerhtml值 - keeping a innerhtml value from a javascript after a html form submit 想要附加URL以及要使用HTML的Get请求提交表单 - want to append URL as well as want to submit the form with Get request of HTML HTML表单上的多个输入值以javascript提交 - Multiple input value on an HTML form submit in javascript 从javascript提交表单后,如何通过提交按钮保持php $ _GET值? - How to keep php $_GET value from a submit button after form submit from javascript? 如何从 firebase 数据库获取最后一个值到 JavaScript? - How to get last value from firebase database to JavaScript? 如何从web javascript中的firebase数据库中获取倒数第二个值? - how to get second last value from firebase database in web javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM