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.

4 Answers 4

1

Use the double dollar sign for this:

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

on jsFiddle

Sign up to request clarification or add additional context in comments.

4 Comments

And how in this case i need to send ajax? Just data: $$('input[name="database[]"]') ?
@user1692333 You'd need serialize your data in some way, maybe have a look at How to convert form data to object using MooTools
Did you try this: mootools.net/forge/p/element_serialize? Else: Try jQuery. It's much more up to date and has tons of tutorials/tips.
the problem is that in joomla by default is mootols
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

2 Comments

$('input[name="database[]"]'​​​​​​​​​​​​​​) is used in the question.
@DanLee i have updated my answer, well i guess OP will have to escape array operator
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.