View Full Version : Resolved Transfer javascript variable to bash script

01-17-2012, 11:40 PM
I have this code to prompt for text input and then I want to run script.sh:

<script type="text/javascript">
function runscript()
var x=prompt("Enter text:");
//this is where I'm lost
var xmlhttp=new XMLHttpRequest();

Is it possible to substitute x above as the value for $txt in script.sh which looks like this below and how please?


echo "Content-type: text/html"
echo ""

<some xmlrpc command> "add text $txt"


01-18-2012, 02:14 AM
You need to pass the value either using GET or POST and then read it in from that spot on the server.

If you use GETthe javaScript to send the value would be:


01-18-2012, 09:01 PM
Thanks for the input.

Well I tried that but I can't get script.sh to read x. I've checked my Apache2 error log and there's nothing showing up other than the deliberate errors I put in to make something show up. I know the script works but maybe something I'm not doing right.

It's almost as if it's working but x is being missed.


01-18-2012, 09:30 PM
You might need to ask about how to read in the querystring in a forum that deals with that server side language.

01-18-2012, 10:49 PM
Yes I believe your right. Thanks for getting me this far. I have tried a number of things but with no success.



01-19-2012, 05:44 PM
Just to add, the method I used to solve this problem was to change my script.sh to perl with a few extra lines which together with your line of code suggested yesterday solved my problem.