0

I'm creating a form in which there are 2 variables namely 'vkey' and 'gene+varient' which is obtained by JS code. The value is displayed correctly in the html form, just that I cant POST this value when I submit the form. How can I POST the 2 mentioned values when I submit the form?

<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>
1
  • Assign the values to hidden inputs Commented Nov 19, 2019 at 18:14

1 Answer 1

1

You just need to set the variables equal to the value in your hidden fields, like:

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

Should give you:

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.