0
   <form action:"" name="sample" method="post"/>
    Firstname:<input type="text" name="firstname" /><br>
     Lastname:<input type="text" name="lastname"/><br>
     DOB:<input id="datepicker" /><br>
    Email:<input type="text" name="email"/><br>
    Gender:
     <input type="radio" name="Male" value="Male"/> Male
   <input type="radio" name="Female" value="Female"/> Female<br>
    Address: <textarea name="address" rows="2" cols="20"></textarea><br>
      <input type="submit" value="Submit" />
        </form>

I need the json output like

   {"Firstname":"","Lastname":"","Email":"","Address":""}
undone
  • 7,857
  • 4
  • 44
  • 69
user2786525
  • 11
  • 1
  • 5
  • I edited the question,s Now, it makes scene! – undone Sep 17 '13 at 07:36
  • Easy: `var json = '{"Firstname":"","Lastname":"","Email":"","Address":""}';`. If you want proper help, you have to provide a proper explanation if your problem and include your attempts to solve it. See http://stackoverflow.com/help/how-to-ask. – Felix Kling Sep 17 '13 at 07:36
  • @undone: makes scene? Isn't it sense you mean? As for the question, it really isn't clear what you want. – jdepypere Sep 17 '13 at 08:02
  • I don't understand why this question was reopened. It still is unclear what the OP wants. Do they want to generate JSON on the server or client side? But even if that was clear, the question is off-topic because *"Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results."* – Felix Kling Sep 17 '13 at 08:19
  • @arbitter Sorry, yes, I meant that! – undone Sep 17 '13 at 08:36

3 Answers3

1

You can get the desired JSON as follows:

var obj = new Object();
obj.FirstName="first";
obj.LastName="Last";
obj.DOB="1/1/1990";
obj.Gender="Male";
obj.Address="Test Address";

alert(JSON.stringify(obj));
Tushar
  • 140
  • 7
0
<?php
//We have a post
if ($_POST) {
  $data = json_encode($_POST);
  var_dump($data);
}
Michal
  • 1,010
  • 2
  • 8
  • 18
0

If you want to post it as a json object then you could use jQuery (see the second link).

How to post a complex HTML form as JSON?

Serializing to JSON in jQuery

Community
  • 1
  • 1
Adam Labi
  • 436
  • 7
  • 16
  • For the future, don't post answers that just contain links to other question. If you think that answers to other questions would solve this question, comment and/or flag/vote to close this question once you have enough reputation. – Felix Kling Sep 17 '13 at 08:25