user2786525
user2786525

Reputation: 11

Json output from html code

   <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":""}

Upvotes: 0

Views: 272

Answers (3)

Tushar
Tushar

Reputation: 140

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));

Upvotes: 1

Adam Labi
Adam Labi

Reputation: 444

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

Upvotes: 0

Michal
Michal

Reputation: 1038

<?php
//We have a post
if ($_POST) {
  $data = json_encode($_POST);
  var_dump($data);
}

Upvotes: 0

Related Questions