How to get the Specific Form Field value using JQuery

I have a form

<form id="post_comment" action="cmt.php" method="post"> <input type="hidden" name="type" value="sub" /> <textarea id="body"></textarea> </form>

I am accessing the form using this code

$("#post_comment").submit(function(event){ var form = $(this); });

How can I get the value of <input type="hidden" name="type" value="sub" /> from this form. I tried to get using form.input("type") but it is not working.


$("#post_comment").submit(function(event){ var inputValue = $("input[name='type']",this).val(); });


Try using an id like this:

<form id="post_comment" action="cmt.php" method="post"> <input type="hidden" id='hidden' name="type" value="sub" /> <textarea id="body"></textarea> </form>

and later:

$("#post_comment").submit(function(event){ var hiddenValue = $("#hidden").val(); });


var form = $(this); var inputValue = form.find('input[name="type"]').val(); or var form = $(this); var inputValue = form.find('input:hidden').val();


<form id="post_comment" action="" method="post"> <input type="hidden" class="hidden" name="type" value="sub" /> <textarea id="body"></textarea> <input type="submit" value="submit" class="submit"/> </form> $(".submit").click(function(){ var hiddenVal=jQuery("#post_comment .hidden").val(); //alert(hiddenVal); });


$("#post_comment").submit(function(event){ var form = $("input[name='type']").val(); })


  • how to resolve OAuthException: (#100)
  • insert radio value multiple data codeigniter in database to one row?
  • Universal Image Loader reuse images
  • Validate child input components on submit with Vee-Validate and vue js 2
  • saving file generated by TCPDF
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Play WS (2.2.1): post/put large request
  • jQuery .attr() and value
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Spring security and special characters
  • Trying to switch camera back to front but getting exception
  • what is the difference between the asp.net mvc application and asp.net web application
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Matrix multiplication with MKL
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • -fvisibility=hidden not passed by compiler for Debug builds
  • How do I configure my settings file to work with unit tests?
  • Memory offsets in inline assembly
  • embed rChart in Markdown
  • How to stop GridView from loading again when I press back button?
  • Turn off referential integrity in Derby? is it possible?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Programmatically clearing map cache
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize