我正在创建一种形式,其中有两个变量,即“ vkey”和“ gene + varient”,这是通过JS代码获得的。
该值正确显示在html表单中,只是我提交表单时无法发布该值。
提交表单时如何过帐上述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>