Q:

Send a value from a cookie to a script

A user input form on my site sends values to a script located on a different server:
<form action="https://mycompany.formprocessor.com/script/" method="post" name="MyForm" onsubmit="return myFunction();"> etc.
I am recreating that form with a modified functionality. Instead of sending the form values directly, I save them in a cookie, and only then, when a certain event happens, I want to send input values from that cookie to the script located at the url provided as the value for action attribute. 
Something like this:
on event {
 // send cookie value to https://mycompany.formprocessor.com/script/ using "post" method;
}

How can this be done?

A:

First of all, you will need to use some cookie functions to store the values in cookie(s) and then access the input values you have saved in those cookie(s). Some cookie functions with explanation how to use them are here: http://www.codelib.net/javascript/cookies.html
Then you will need to have a way of sending the data across domains. To do that I suggest that you use a form containing a hidden field and then submit that form to the other server.
Like this:
<form method="post" action="https://mycompany.formprocessor.com/script/">
<input type="hidden" id="hiddendata" name="data" />
</form>

<script>
function onEvent() { /* call this function when your desired event happens */
  var cookiedata = readCookie('cookiename');
  var datafield = document.getElementById('hiddendata');
  datafield.value = cookiedata;
  datafield.form.submit();
}
</script>

Note that I suggest you have the program at formprocessor return 204 No Content as its HTTP status code so that the document itself is not reset. Otherwise the browser will replace the current page with the contents of https://mycompany.formprocessor.com/script/ after the data is submitted. This is the a way of doing AJAX that does not block cross-domain requests.
The following method will only work if you are content with using GET requests to send the data to the server.
You can set the src attribute of included elements on the page, like an img element, to a URL like this (initial image is from http://commons.wikimedia.org/wiki/File:1x1.png)
<img id="hiddenimage" width="1" height="1" src="1x1.png" />

<script>
function onEvent() { /* call this function when your desired event happens */
  var cookiedata = readCookie('cookiename');
  var dataimage  = document.getElementById('hiddenimage');
  dataimage.src = 'https://mycompany.formprocessor.com/script/?data=' + encodeURIComponent(cookiedata);
}
</script>

