It's a good question; in fact, I find it really strange that jQuery doesn't have a function that does precisely this. First, it selects the HTML element with the ID "deftext". Stack Overflow for Teams is moving to its own domain! Discuss. Should we burninate the [variations] tag? We provide articles and tutorials to solve coding problems in real world. The .val() method is primarily used to get the values of form elements such as input, select and textarea. When used to set value: This method sets the value of the value attribute for ALL matched elements. 'It was Ben that found it' v 'It was clear that Ben found it', Earliest sci-fi film or program where an actor plays themself, Make a wide rectangle out of T-Pipes without loops, LO Writer: Easiest way to put line of words into table as rows (list). To change the radio button that is selected youd do this: [0] would set the first one checked, [1] would set the second one checked and so on. The .val() method allows setting the value by passing in a function. What does "use strict" do in JavaScript, and what is the reasoning behind it? Load the jQuery input-value plugin after jQuery library. I was using this but my form has various hidden elements (not hidden as in type I mean visually) which I wouldn't want included in the serialize. Why can we add/substract/cross out chemical equations for Hess law? Trying to figure out why this input value can't be extracted from this function: function valEmail(selname) { $('form.cd-form input[name^="email"]').each(function(selname) Get form input value inside function - jQuery Forum How to get form data using JavaScript/jQuery? This code snippet is used to get the closest form (related form) of the submit button. There are several methods are used to get an input textbox value without wrapping the input element inside a form element. Easy, give the field a property, for example ignore_this: Thanks for contributing an answer to Stack Overflow! Description "$ ("input [name=myname]")" Selects all elements matched by <input> that have a name value exactly equal to myname.. Syntax Here is the simple syntax to use this selector $ ("element [attribute-name=attribute-value]") Parameters Here is the description of all the parameters used by this selector Now we need to get the input text data of the form, so we can use the val () function as var name =$ ("#fname").val ();", where "#fname" is the id of the input element. serialize() is the best method. Dipaks solution worked though. We will have a select element followed by a multiple option element. Thanks to the tip from Simon_Weaver, here is another way you could do it, using serializeArray: Note that this snippet will fail on