Welcome Guest, Not a member yet? Register   Sign In
[WORKED AROUND] Passing a checkbox array... Nerve-racking.
#1

[eluser]Morty[/eluser]
Hi there !

My code is partly based on Derek Allard sample application. However I need to pass a checkbox array to my CI AJAX receiver:

Code:
$filter = $this->input->post('filter');

Without AJAX it works gracefully but when I try to pass the array through via the following JS function, it does not look like my standard array.

JS function:
Code:
function inline_results() {
    $filterstring = '';

    res = document.getElementsByName('filter[]')
    for (i = 0; i < res.length; i++)
        if (res[i].checked == true)
            $filterstring += '&filter;[]=' + res[i].value;

    if ($filterstring == '')
        $filterstring = '&filter=false';

    alert('stock_site='+$F('stock_site'+'&stock;_product='+$F('stock_product'+$filterstring);

    new Ajax.Updater ('stock_values', base_url+'stocks/ajaxstocksearch', {method:'post', postBody:'stock_site='+$F('stock_site')+'&stock;_product='+$F('stock_product')+$filterstring});

There should be a way to obtain the same array as if it was posted by a standard form. At the moment, what I get from this is :

1. 'ITEM1' and 'ITEM2' checked : array('ITEM1' = 0, 'ITEM2' = 1); => Nearly what I want
2. 'ITEM3' checked with or without other choices : 'ITEM3' never shows up;
3. Nothing checked : string false. => Not exactly what I want but I can convert it.

I can post other details if it can help you to put me on the right tracks.

Thanks in advance,
Morty

P.S: It seems that ";" are being added in my code by the forum. They don't exist in my actual code.


Messages In This Thread
[WORKED AROUND] Passing a checkbox array... Nerve-racking. - by El Forum - 08-02-2007, 02:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB