user2531749
user2531749

Reputation: 13

pass a javascript variable within a html page into a html form (on the same page) for submission to perl cgi

<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?

Upvotes: 1

Views: 17903

Answers (2)

Trylks
Trylks

Reputation: 1498

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.

Upvotes: 2

vladkras
vladkras

Reputation: 17228

you can write it directly:

<script type="text/javascript">
document.write('<input type="hidden" name="ID" value="'+id+'"/>');
</script>

Upvotes: 6

Related Questions