Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9171397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:09:25+00:00 2026-06-17T16:09:25+00:00

Here’s a strange problem. I have the following javascript code: function doTransfer(target, source) {

  • 0

Here’s a strange problem.

I have the following javascript 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 < len; i ++)
    {
        text = trim(tempText[i]);
        if(text)
            targetText.push(text);
    }
    var sourceObj = f_getElement(source);
    len = sourceObj.options.length;
    for(i = 0; i < 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 && (searchArray(targetText, selection) == -1))
            targetText.push(selection);
    }
    targetObj.value = targetText.join(',');
}

function f_getElement(id)
{
    return document.getElementById(id);
}

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).

Let’s say I transfer 3 selections (‘aaa’, ‘aaaa’, ‘aaaaa’), then I get ‘aaa,aaaa,aaaaa’ in the textarea. This is what I want.

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’.

Some things I’ve noticed:

  1. ‘aaa,aaaa’ transferred appears correctly in $_POST.
  2. ‘aaaaa’ transferred appears correctly in $_POST.
  3. ‘aaa,aaaaa’ transferred appears correctly in $_POST.
  4. The same error and successes appear with similar variations of ‘b’.
  5. ‘UT1,UT2,UT3,UT4,UT5’ transferred appears correctly in $_POST.
  6. *If I type ‘aaa,aaaa,aaaaa’ into the textarea, it does appear correctly in $_POST.*

I am quite puzzled and don’t know where to begin to track the problem down.

Regards,

Mark

gateway function:

/**
* 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 < 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 < 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 && 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) && (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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:09:26+00:00Added an answer on June 17, 2026 at 4:09 pm

    Ok i found the bug, it is an base64 encoding problem.

    First an jsFiddle with broken code:
    http://jsfiddle.net/mexd7/2/

    Oben Firebug console:
    https://getfirebug.com/logging

    and play some around with adding words and look what you see.

    Now here the fixed version:
    http://jsfiddle.net/mexd7/1/

    function decode_base64(s)
    {
        var e={},i,k,v=[],r='',w=String.fromCharCode;
        var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];
    
        for(z in n) {
            for(i=n[z][0];i<n[z][1];i++) {
                v.push(w(i));
            }
        }
    
        for(i=0;i<64;i++) {
            e[v[i]]=i;
        }
    
        for(i=0;i<s.length;i+=72) {
            var b=0,c,x,l=0,o=s.substring(i,i+72);
            for(x=0;x<o.length;x++) {
                c=e[o.charAt(x)];b=(b<<6)+c;l+=6;
                while(l>=8) {
                var charCode = (b>>>(l-=8))%256;
    
                    if (charCode > 31) {
                        // only add printable chars
                        r+=w(charCode);
                    }
                }
            }
        }
        return r;
    }
    

    It seams there is a problem in your base64 encoder but i solved it with the decode.
    By dont adding not prinable chars like \0 to the string.

    http://www.asciitable.com/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here's the code I have. It works. The only problem is that the first
Here is the code in a function I'm trying to revise. This example works
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is my problem: I have a chatapplication and the messages are displayed in
Here is the code in which i am having the problem- <!DOCTYPE html> <html>
Here is the code I have. This is my PrintToFile class import java.util.*; import
Here is my problem.. I have the option to create(add) two new input fields,
Here's the problem....I have three components...A Page that contains a User Control and a
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.