select box to textarea to PHP: transfer not appearing in $_POST
<p>Here's a strange problem.</p>

<p>I have the following javascript code:</p>

<pre><code>function doTransfer(target, source)
{
    var targetObj = f_getElement(target);
    var tempText = targetObj.value.split(',');
    var len = tempText.length;
    var targetText = new Array;
    var text;
    var selection;
    var split;
    for(var i = 0; i &lt; len; i ++)
    {
        text = trim(tempText[i]);
        if(text)
            targetText.push(text);
    }
    var sourceObj = f_getElement(source);
    len = sourceObj.options.length;
    for(i = 0; i &lt; len; i++)
    {
        split = sourceObj.options[i].value.split('_');
        selection = decode_base64(split[1]);
// When searching for existing word, we ignore case as different words may be indicated by different use of case on the same letters.
// i.e. we trust the user to get it right.
        if(sourceObj.options[i].selected &amp;&amp; (searchArray(targetText, selection) == -1))
            targetText.push(selection);
    }
    targetObj.value = targetText.join(',');
}

function f_getElement(id)
{
    return document.getElementById(id);
}
</code></pre>

<p>This all works fine and transfers multiple selections (base64_encoded) from a select box to the target textarea (base64_decoded -- javascript code not shown here).</p>

<p>Let's say I transfer 3 selections ('aaa', 'aaaa', 'aaaaa'), then I get 'aaa,aaaa,aaaaa' in the textarea.  This is what I want.</p>

<p>I then click on the submit button but, instead of getting 'aaa,aaaa,aaaaa' in my $_POST variable for the textarea, I get just 'aaa,aaaa'.</p>

<p>Some things I've noticed:</p>

<ol>
<li>'aaa,aaaa' transferred appears correctly in $_POST.</li>
<li>'aaaaa' transferred appears correctly in $_POST.</li>
<li>'aaa,aaaaa' transferred appears correctly in $_POST.</li>
<li>The same error and successes appear with similar variations of 'b'.</li>
<li>'UT1,UT2,UT3,UT4,UT5' transferred appears correctly in $_POST.</li>
<li>*If I <strong>type</strong> 'aaa,aaaa,aaaaa' into the textarea, it does appear correctly in $_POST.*</li>
</ol>

<p>I am quite puzzled and don't know where to begin to track the problem down.</p>

<p>Regards,</p>

<p>Mark</p>

<p>gateway function:</p>

<pre><code>/**
* Gateway to AJAX javascript functions
* @param input - JSON string representing an array of sets of instructions to be processed in numerical order. At the very
* least a startFunction() method should be present in each set.
*/
function gateway(input)
{
    var parsedInput = JSON.parse(input);
    var inputLen = parsedInput.length;
    if(gateway.aobj_index == undefined)
        gateway.aobj_index = -1;
    gateway.aobj_index++;
    for(var i = 0; i &lt; inputLen; i++)
    {
        if(parsedInput[i].startFunction != undefined)
        {
            A_OBJ[gateway.aobj_index] = new AJAXOBJECT();
            A_OBJ[gateway.aobj_index].input = parsedInput[i];
            A_OBJ[gateway.aobj_index].evalReturn = eval('(' + A_OBJ[gateway.aobj_index].input.startFunction + '())');
            if(A_OBJ[gateway.aobj_index].evalReturn == false)
            {
                return false;
            }
        }
        else
        {
            alert('No startFunction() defined');
            return false;
        }
        gateway.aobj_index++;
    }
    return true;
}

/**
* The object used for independent AJAX instances
*/
function AJAXOBJECT()
{
//properties
    this.input = null;
    this.processedScript = null;
    this.phpResponse = null;
    this.targetObj = null;
    this.evalReturn = null;
// methods
    this.checkInput = checkInput;
    this.doXmlHttp = doXmlHttp;
}

/**
* Check required input parameters are present in input
* @param input array
* @return false|true
*/
function checkInput(inputArray)
{
    var len = inputArray.length;
    for(var i = 0; i &lt; len; i++)
    {
        if(this.input[inputArray[i]] == undefined)
        {
            alert('required input parameter is missing: ' + inputArray[i]);
            return false;
        }
    }
    return true;
}

/**
* Create the xmlHttp object
* @return xmlHttp object
*/  
function createXmlHttpObject()
{
    var xmlHttp = false;
//Check if we are using IE.
    try
    {
//If the javascript version is greater than 5.
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e)
    {
//If not, then use the older active x object.
        try
        {
//If we are using IE.
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E)
        {
//Else we must be using a non-IE browser.
            xmlHttp = false;
        }
    }
//If we are using a non-IE browser, create a JavaScript instance of the object.
    if (!xmlHttp &amp;&amp; typeof XMLHttpRequest != undefined)
    {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

/**
* Execute the xmlHTTP object
*
* @return true|false
*/
function doXmlHttp()
{
    if(this.targetObj == null)
    {
        alert('No AJAXOBJECT targetObj property set');
        return false;
    }
    if(this.processedScript == null)
    {
        alert('No AJAXOBJECT processedScript property set');
        return false;
    }
    var targetObj = this.targetObj;
    var xmlHttp = createXmlHttpObject();
    xmlHttp.open("GET", this.processedScript, true);
//alert(this.processedScript);
    xmlHttp.onreadystatechange = function()
    {
        if((xmlHttp.readyState == 4) &amp;&amp; (xmlHttp.status == 200))
        {
            try
            {
                this.phpResponse = JSON.parse(xmlHttp.responseText);
            }
            catch(err)
            {
                alert('HTTP status: ' + xmlHttp.status + '. ' + err.message + ' ERROR. PHP says:\n' + xmlHttp.responseText);
                return false;
            }
            if(this.phpResponse.ERROR)
            {
                alert('PHP ERROR:\n' + this.phpResponse.ERROR);
                return false;
            }
            if(this.phpResponse.innerHTML)
                targetObj.innerHTML = this.phpResponse.innerHTML;
//alert(this.phpResponse.next);
// Further action to be taken?
            if(this.phpResponse.next != undefined)
                gateway(JSON.stringify([this.phpResponse]));
        }
    }
    xmlHttp.send(null);
    A_OBJ[gateway.aobj_index].xmlHttp = xmlHttp;
    return true;
}
/**
* Get an object for the requested HTML element ID
* @return element object
*/
function f_getElement(id)
{
    return document.getElementById(id);
}
</code></pre>
