开发者

How get the values of a text field with mootools?

Hi i have in my form a text field like this

<input type="text" name="optionsArray[]" class="pollOptionInput">

and i wa开发者_开发知识库nt to get those values they can be value 1 = 123 value 2= foo value 3= bar etc the list can go on.

i want to get those values so i can pass them to my controller via ajax.


not sure if I read this correctly - are all the fields going to have the same name?

if so, this works:

var vals = document.getElements("input.pollOptionInput[name='optionsArray[]']").get("value");
console.log(vals);

on markup

<input type="text" value="foo" name="optionsArray[]" class="pollOptionInput">

<input type="text" value="boo" name="optionsArray[]" class="pollOptionInput">

<input type="text" value="bar" name="optionsArray[]" class="pollOptionInput">

results in:

["foo", "boo", "bar"]

you need mootools 1.2+ to be guaranteed parsing of the name property as is, it will fail in 1.11/1.12

update:

new Request.JSON({
    'method': 'post',
    'url': en4.core.baseUrl + 'wall/createpoll/',
    'data': {
        'poll_title': poll_title,
        'poll_description': poll_description,
        'poll_privacy': poll_privacy,
        'poll_comment': poll_comment,
        'options': vals
    }
}).send();

new Request.JSON({
    'method': 'post',
    'url': en4.core.baseUrl + 'wall/createpoll/',
    'data': document.id("formName") // serialize all input fields of a form.
}).send();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜