javascript - 将 JavaScript 中的值集成到 HTML 表单中以将其发布到 php 中

标签 javascript php html

我正在创建一个表单,其中有 2 个变量,即“vkey”和“gene+varient”,这是通过 JS 代码获取的。 该值在html表单中正确显示,只是我在提交表单时无法POST该值。 提交表单时如何发布提到的 2 个值?

<form action="acmg_controller.php" method="POST" target="_blank">
    <p>
        Source:
        <select name="source">
            <option value="pubmed">PubMed</option>
            <option value="other">other</option>
        </select>
        PMID:
        <input type="text" name = "pmid" style="width: 80px"> <br>
        <input type="hidden" name="vkey" id="pvkey">
        vkey:
        <script>
            var hashParams = window.location.hash.substr(1).split('&');
            var temVkey = hashParams[2].split('=');
            var vkey = temVkey[1];
            document.write(vkey);
        </script> <br>
        gene+varient
        <input type="hidden" name="genevar">
        <script>
            var hashParams = window.location.hash.substr(1).split('&');
            var temvarient = hashParams[1].split('=');
            var varient = temvarient[1];
            var hashParams_ = window.location.hash.substr(1).split('&');
            var temgene = hashParams_[0].split('=');
            var gene = temgene[1];
            document.write(gene+' '+varient);
        </script> <br>
    </p>        
    <label>Summary:</label> <br>
    <textarea style = "width: -webkit-fill-available;height: 400px" name="text"> 
    </textarea> <br><br>
    <input type="submit" value="Submit">
</form>

最佳答案

您只需将变量设置为等于隐藏字段中的值,例如:

document.getElementById('pvkey').value = vkey;

应该给你:

<form action="acmg_controller.php" method="POST" target="_blank">
    <p>
        Source:
        <select name="source">
            <option value="pubmed">PubMed</option>
            <option value="other">other</option>
        </select>
        PMID:
        <input type="text" name = "pmid" style="width: 80px"> <br>
        <input type="hidden" name="vkey" id="pvkey">
        vkey:
        <script>
            var hashParams = window.location.hash.substr(1).split('&');
            var temVkey = hashParams[2].split('=');
            var vkey = temVkey[1];
            document.write(vkey);
            document.getElementById('pvkey').value = vkey;
        </script> <br>
        gene+varient
        <input type="hidden" name="genevar" id="genevar">
        <script>
            var hashParams = window.location.hash.substr(1).split('&');
            var temvarient = hashParams[1].split('=');
            var varient = temvarient[1];
            var hashParams_ = window.location.hash.substr(1).split('&');
            var temgene = hashParams_[0].split('=');
            var gene = temgene[1];
            document.write(gene+' '+varient);
            document.getElementById('genevar').value = gene+' '+varient;
        </script> <br>
    </p>        
    <label>Summary:</label> <br>
    <textarea style = "width: -webkit-fill-available;height: 400px" name="text"> 
    </textarea> <br><br>
    <input type="submit" value="Submit">
</form>

关于javascript - 将 JavaScript 中的值集成到 HTML 表单中以将其发布到 php 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58940357/

相关文章:

javascript - 在html中创建6个复选框

javascript - 我可以允许出于开发目的对不安全的来源进行地理定位吗?

php - 如何创建一个php(jquery)幻灯片切换信息目录

html - 如何在 dive 标签中添加 onclick 事件

javascript - 如何将加载 UpdatePanel 内容推迟到页面呈现之后?

javascript - 无法从 Node js中的函数返回数据

php - Linkedin 共享 API 403 访问被拒绝

php - 函数 : Database connection in function or pass it as argument? 的最佳情况是什么

html - 当文本对齐在 CSS3 中不起作用时获取背景图像以居中对齐

html - 如何在 HTML 文本区域中显示样式