Are you a jQuery user? Will you have other HTML inputs tags to collect user input from? The reason I ask is that there are different paths to the end result, and most people have preferences as to the way it's done. You can put input tags into a "form" tag and get the entire form as as object, or you can get individual input types and combine the data. One problem with using a form tag is that the action attribute can cause your web app to disappear unless you prevent the default action.
The way I do it is by getting all input elements by tag name and looping through them to retrieve the value. I give every element an "id" name so that your server code knows what value goes with what.
If the html input element type is either checkbox or radio then the value must be retrieved by accessing the "checked" attribute rather than the "value" attribute.
This code lacks some detail but hopefully gives you the process of getting the input values. You should stringify the object before sending it to the server. There are other ways of doing it. This is my preference which may not be other people's idea of the best way to do it.
var o = {};//object for return
var b = ;//Get the element that is holding the input elements.
var thisArr = b.getElementsByTagName('input');//Assign all Inputs thisArr
for () {//Loop through the array of all the input elements
var thisEl = thisArr[i];//Get one element
var elementType = thisEl.type;//Get the type of the element
var elID = thisEl.id;//Get the element id
var inputValue = ['checkbox','radio'].indexOf(
elementType) !== -1 ? thisEl.checked : thisEl.value;//If this input type is checkbox
//or radio the use checked property else use value property
//console.log('
inputValue : ' +
inputValue );
//Put the input value into an object
o[elID] = inputValue;
}
return o;