Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1779 Can I pass JavaScript variables to a CGI Perl program?

You are here: irt.org | FAQ | JavaScript | Form | 7.3 | Q1779 [ previous next ]

You can send the variable using POST or GET by using a form. You can write the form when the function is invoked or you can use anpre-written form.

==================
Pre-written form (declare form in htmlcode):
==================

<html>
<head>
<script language="javascript">
function Sendvalues() {
  var firstname = 'Jason';   //  JavaScript variable containing firstname
  document.forms('cgivalues').firstname.value=firstname;
  document.forms('cgivalues').submit();
}

</head>
<body>

<form name="cgivalues" action="POST" action="script.pl">
<input type="hidden" name="firstname">
</form>

</body>
</html>

=====================
Invoked function form
=====================

var firstname = 'Jason';   //  JavaScript variable containing firstname

document.write('<form name="cgivalues" action="POST" action="script.pl">';
document.write('<input type="hidden" name="firstname" value="'+firstname+'">';
document.write('</form>');

document.forms('cgivalues').submit();

Submitted by Patrick van Lier

©2018 Martin Webb