0

I have simple line witch returns me error

Window.addEvent('domready', function(){
    function sendPost(){
        var values = $('input[name="database[]"]'​​​​​​​​​​​​​​).map(function(e) { return e.value; });
    // var myRequest = new Request({
    //  url: '<?php echo JURI::root();?>administrator/index.php?option=com_component',
    //  method: 'post',
    //  data: values

    // });

    // myRequest.send();
}
});

And here is error. error p.s. My script is after mootols.

user1692333
  • 2,461
  • 5
  • 32
  • 64

4 Answers4

1

Use the double dollar sign for this:

$$('input[name="database[]"]')

on jsFiddle

dan-lee
  • 14,365
  • 5
  • 52
  • 77
  • And how in this case i need to send ajax? Just `data: $$('input[name="database[]"]')` ? – user1692333 Oct 29 '12 at 11:26
  • @user1692333 You'd need serialize your data in some way, maybe have a look at [How to convert form data to object using MooTools](http://stackoverflow.com/a/4567448/612202) – dan-lee Oct 29 '12 at 11:28
  • Did you try this: http://mootools.net/forge/p/element_serialize? Else: Try jQuery. It's much more up to date and has tons of tutorials/tips. – dan-lee Oct 29 '12 at 11:37
  • the problem is that in joomla by default is mootols – user1692333 Oct 29 '12 at 12:45
0

Change

var values = $('input[name="database[]"]'​​​​​​​​​​​​​​).map(function(e) { return e.value; });

to

 var values = $('input[name=database\[\]]'​​​​​​​​​​​​​​).map(function(e) { return e.value; });//escape array operator
Sibu
  • 4,609
  • 2
  • 26
  • 38
  • `$('input[name="database[]"]'​​​​​​​​​​​​​​)` is used in the question. – dan-lee Oct 29 '12 at 11:01
  • @DanLee i have updated my answer, well i guess OP will have to escape array operator – Sibu Oct 29 '12 at 11:04
0

The code bellow will post it and in PHP you access it with $_REQUEST['somename']

Window.addEvent('domready', function(){
function sendPost(){
    var values = $('input[name="database[]"]'​​​​​​​​​​​​​​).map(function(e) { return e.value; });
    new Request({
        url: '<?php echo JURI::root();?>administrator/index.php?option=com_component',
        method: 'post',
        data: {
            'somename': values
        }

    }).send();
}
});

However, it it's a form you would like to post you can do it in Mootools with Form.Request, see http://mootools.net/docs/more/Forms/Form.Request for more information.

If you add some more information I could probably help you a bit more when it comes to Mootools (not Joomla). For instance, you are not doing anything with the data coming back from the server.

Edit: There is another way to get the form data as well:

$('theForm').toQueryString().parseQueryString();

So you can use it as:

Window.addEvent('domready', function(){
function sendPost(){
    new Request({
        url: '<?php echo JURI::root();?>administrator/index.php?option=com_component',
        method: 'post',
        data: $('theForm').toQueryString().parseQueryString();
    }).send();
}
});

Edit #2: You are aware that in your code in the example you do not call the function sendPost? so it actually don't do anything and does not have to be attached to the domready event.

j0k
  • 22,600
  • 28
  • 79
  • 90
Nils
  • 2,041
  • 1
  • 15
  • 20
0
var database = ($$('input[name="database[]"]').map(
    function (element) {
        return 'database[]=' + element.get('value');
    }
)).join('&');

This produces a string ready to be used for passing data in a HTTP request:

database[]=<value-0>&database[]=<value-1>&database[]=<value-N>

Easy as pie.

Carlos
  • 4,949
  • 2
  • 20
  • 37