1
<script type="text/javascript">
var id = getValue("ID");
document.write(id);
</script>    

<form action="cgi-bin/runalg.cgi" method="post" enctype="multipart/form-data">
<input type="radio" name="genome" value="E.Coli"> <i>E.Coli</i> <input type="radio" name="genome" value="Human"> Human<br> 
<input type="submit" name="submit" value="Submit"/>
<input type="reset" name="reset" value="Clear"/>
</form>

</body>

How do I get the value of the JavaScript variable (var id) into the form so that on submission I can retrieve it in the runalg.cgi using the $q<-param("ID") command?

3
  • ; </script> <form action="cgi-bin/runalg.cgi" method="post" enctype="multipart/form-data"> <input type="radio" name="genome" value="E.Coli"> <i>E.Coli</i> <input type="radio" name="genome" value="Human"> Human<br> <input type="submit" name="submit" value="Submit"/> <input type="reset" name="reset" value="Clear"/> </form> </body> HOW DO I GET THE VALUE OF THE JAVASCRIPT VARIABLE (var id) INTO THE FORM SO THAT ON SUBMISSION I CAN RETRIEVE IT IN THE runalg.cgi USING THE $q<-param("ID") command? Commented Jun 28, 2013 at 12:21
  • 2
    Welcome to Stackoverflow. Please edit this into your question and please don't use capslock. It feels as if you shout at the reader... Commented Jun 28, 2013 at 12:26
  • Sorry for that, thanks. Commented Jun 28, 2013 at 12:27

2 Answers 2

6

you can write it directly:

<script type="text/javascript">
document.write('<input type="hidden" name="ID" value="'+id+'"/>');
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

That input is not within the form.
yeah, how did you find this out? he didn't tell us where is the <script> section
2

Add a hidden field. Set the value in that field to the value of the variable in Javascript.

<form action="cgi-bin/runalg.cgi" method="post" enctype="multipart/form-data">
[...]
<input type="hidden" name="ID" value="default">
</form>

And then on javascript:

<script type="text/javascript">
document.forms[0].elements["ID"].value = getValue("ID");
</script>

The index for the form may vary in your document.

5 Comments

if you need "a few minutes to add the code." - change you job
you are welcome, also I have to note that forms[0] points on the first form on the page only, what if he has it under "login", "search" and "subscribe" form?
I will try this as well and see if it works same as that provided by vladkras below, Thanks!
@vladkras Why would you have to note something that I did already note?
@Trylks, sorry, I didn't notice it, but I can show you the better way

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.