Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert form data to object using MooTools

I would like to convert an entire form of data to a javascript object.

<form id='myform'>
   <input type='text' name='field1' value='foo'>
   <input type='text' name='field2' value='bar'>
</form>

would convert to a javascript object...

{
   field1: 'foo',
   field2: 'bar'
}
like image 828
Aldie Avatar asked Jan 29 '10 23:01

Aldie


1 Answers

In MooTools you can do easy trick how to convert all forms values into the Object:

var formObjects=$('myform').toQueryString().parseQueryString();

Convert to JSON:

var formJson=JSON.encode(formObjects);
like image 165
Trebla Avatar answered Sep 22 '22 03:09

Trebla