JSFiddle - React, Tailwind, and code Playground

by Achilleterzo

HTML

<form action="javascript:alert('success!');">
    <div>
      <input name="myInput" type="text" />
      <input name="myInput2" type="text" />
      <input type="submit" />
    </div>
  </form>
  <span></span>

CSS

p { margin:0; color:blue; }
  div,p { margin-left:10px; }
  span { color:red; }

JavaScript

$("form").submit(function()
{
    //Checking data here:
    $("input").each(function(i, obj)
    {
    });
    alert($(this).serialize());
    alert(toJSON($(this).serializeArray()));
    //return false;
});

function toJSON(obj)
{
    var json = '({';
    $.each(obj, function(k,v){
    var q = typeof v == 'string' ? ~v.indexOf("'") ? '"' : "'" : '';
    if (typeof v == 'object')
    v = toJSON(v).slice(0,-1).substr(1);
    json+= k + ':'+ q + v + q + ',';
    });
    return json.slice(0,-1)+'})';
};