Not able to convert form data into JSON object using form2js.js

1.6k views Asked by At

I am using form2js.js for converting my form data into a JSON object.

Here is the code:

var loginData = form2js('loginForm', '.', true);
console.log("FormData=" + JSON.stringify(loginData));

But the JSON String is empty. loginform is the ID of my form. I have searched for help on but I am not getting anything.

Here is the HTML form:

<form action="index.html" class="padder" id="loginForm" name="loginForm">                                
   <label class="control-label">User</label>
   <input id="userId" type="text" placeholder="User ID" class="form-control">                               
   <input type="password" id="password" placeholder="Passcode" class="form-control"> 
   <button type="submit" id="signInBtn" class="btn btn-info">Sign in</button>                               
</form>
1

There are 1 answers

0
Arun P Johny On BEST ANSWER

The problem seems to be the missing name attribute

<form action="index.html" class="padder" id="loginForm" name="loginForm">
    <label class="control-label">User</label>
    <input name="userId" id="userId" type="text" placeholder="User ID" class="form-control" />
    <input name="password" type="password" id="password" placeholder="Passcode" class="form-control" />
    <button type="submit" id="signInBtn" class="btn btn-info">Sign in</button>
</form>

Demo: Fiddle