Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass to cgi script/return to javascript

Status
Not open for further replies.

kenya88

Technical User
Oct 23, 2000
6
US
I have a variable I want to pass to a cgi script. Then have the cgi script process the variable and return it for use in a javascript. Can this be done?

Thanks in advance;

Doug
 
Sure,
To get it to the CGI you could add it to the URL:
location.href='script.cgi?Parameter='+myvar;

or by putting it in a hidden form field and submitting the form:
<script>
document.f.Parameter.value=myval;
</script>
<form name=&quot;f&quot; action=&quot;script.cgi&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;Parameter&quot;>
...
<input type=&quot;submit&quot;>
</form>

To get the variable back into JavaScript, have the CGI write the JavaScript. I use ASP, so I would use:
Response.Write &quot;<script>var myvar=&quot; & myvar & &quot;';</script>&quot;

In PHP it might be something like:
printf(&quot;<script>var myvar='%s'</script>&quot;,$myvar);
 
I just reread your question and thought of an additional comment. If you wanted to do it without leaving/reloading the page, you could send the parameter (using either of the techniques I described above) to a hidden frame and have the script write the output to the hidden frame like:
Response.Write &quot;<script>parent.visibleFrame.myvar='&quot; & myvar & &quot;';</script>&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top