I created a JSP page with few input fields. When i click on submin, i need the javascript to create json object and put input values in it and i want to display the json data in same jsp page.
This is my form
<form name="jsond" method="get">
<br>
<p id="msg"></p>
First Name:
<input type="text" id="firstName"/><br>
Last Name:
<input type="text" id="lastName"/><br>
E-mail:
<input type="text" id="email"/><br>
Mobile No:
<input type="text" id="mobile"/><br>
Place:
<input type="text" id="place"/><br>
Country:
<input type="text" id="country"/><br>
<br>
<input type="submit" name="submit" value="Submit" onclick="return submitForm(this, event);">
</form>
And this is my script
function submitForm(thisObj, thisEvent) {
var firstName = document.forms["jssond"]["firstName"].value;
var lastName = document.forms["jssond"]["lastName"].value;
var email = document.forms["jssond"]["email"].value;
var mobile = document.forms["jssond"]["mobile"].value;
var place = document.forms["jssond"]["place"].value;
var country = document.forms["jssond"]["country"].value;
// How to do the remaining code? I want to store the above variables in json object and display json values in <p id="msg"></p>
How to pass the json object to servlet from javascript?
Thanks