{"id":922,"date":"2012-06-15T19:16:27","date_gmt":"2012-06-15T19:16:27","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=922"},"modified":"2012-06-15T19:16:27","modified_gmt":"2012-06-15T19:16:27","slug":"jquery-form-selectors-examples-jquery-form-selectors-reference","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-form-selectors-examples-jquery-form-selectors-reference\/","title":{"rendered":"jQuery Form Selectors Examples \/ References"},"content":{"rendered":"<p>Do you know what there are many form selectors in jQuery and it&#8217;s very easy to access the form elements very easily with just few lines of code. In this article, I am going share\u00a0<em><strong>jQuery Form Selectors Examples<\/strong><\/em> with you for a better understanding of how the\u00a0jQuery Form Selectors work.<!--more--><\/p>\n<h2>jQuery Form Selectors Examples<\/h2>\n<h2>1. TextBox \u2013 $(&#8220;input:text&#8221;)<\/h2>\n<h3>Select a textbox using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:text\");<\/pre>\n<h3>Get textbox value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:text\").val();<\/pre>\n<h3>Set textbox value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:text\").val(\"This is some custom text.\");<\/pre>\n<h2>2. Textarea \u2013 $(&#8220;textarea&#8221;)<\/h2>\n<h3>Select a textarea using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"textarea\");<\/pre>\n<h3>Get textarea value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"textarea\").val();<\/pre>\n<h3>Set textarea value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"textarea\").val(\"This is some custom text.\");<\/pre>\n<h2>3. Password \u2013 $(&#8220;input:password&#8221;)<\/h2>\n<h3>Select a password using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:password\");<\/pre>\n<h3>Get password value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:password\").val();<\/pre>\n<h3>Set password value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:text\").val(\"This is some custom text.\");<\/pre>\n<h2>4. Radio Buttons \u2013 $(&#8220;input:radio&#8221;)<\/h2>\n<h3>Select a radio button using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:radio\");<\/pre>\n<h3>Get selected radio button option using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:radio[name=radio_button_name]:checked\").val();<\/pre>\n<h3>Select the first radio button option using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$('input:radio[name=radio_button_name]:nth(0)').attr('checked',true);<\/pre>\n<p>or<\/p>\n<pre class=\"lang:js decode:true\">$('input:radio[name=radio_button_name]')[0].checked = true;<\/pre>\n<h2>5. Check Box \u2013 $(&#8220;input:checkbox&#8221;)<\/h2>\n<h3>Select a checkbox using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:checkbox\");<\/pre>\n<h3>To check whether a checkbox is checked using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:checkbox[name=checkbox_name]\").is(':checked');<\/pre>\n<h3>To check a checkbox using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:checkbox[name=checkbox_name]\").attr('checked',true);<\/pre>\n<h3>To unchecked a checkbox using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:checkbox[name=checkbox_name]\").attr('checked',false);<\/pre>\n<h2>6. Select(dropdown box) \u2013 $(&#8220;select&#8221;)<\/h2>\n<h3>Select a dropdown box using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"select\")<\/pre>\n<p>or<\/p>\n<pre class=\"lang:js decode:true\">$(\"#dropdown_id\")<\/pre>\n<h3>Get selected drop down box value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"#dropdown_id\").val();<\/pre>\n<h3>Set drop down box value to a custom value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"#dropdown_id\").val(\"This is some custom value.\");<\/pre>\n<h2>7. Submit button \u2013 $(&#8220;input:submit&#8221;)<\/h2>\n<h3>Select a submit button using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:submit\");<\/pre>\n<h3>Add click event to Submit button using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:submit\").click(function() {\n\/\/Do this\n});<\/pre>\n<h2>8. Reset button \u2013 $(&#8220;input:reset&#8221;)<\/h2>\n<h3>Select a reset button using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:reset\");<\/pre>\n<h3>Add click event to Reset button using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:reset\").click(function() {\n\/\/Do this\n});<\/pre>\n<h2>9. Hidden value \u2013 $(&#8220;input:hidden&#8221;)<\/h2>\n<h3>Select a hidden value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:hidden\");<\/pre>\n<h3>Get hidden value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:hidden\").val();<\/pre>\n<h3>Set hidden value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:hidden\").val(\"This is some custom text.\");<\/pre>\n<h2>10. Upload File \u2013 $(&#8220;input:file&#8221;)<\/h2>\n<h3>Select a file using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:file\");<\/pre>\n<h3>Get file value using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">$(\"input:file\").val();<\/pre>\n<h5>Your Turn!<\/h5>\n<p>Do you know of any other <em><strong>jQuery form selectors<\/strong><\/em>? Feel free to share by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you know what there are many form selectors in jQuery and it&#8217;s very easy to access the form elements very easily with just few lines of code. In this article, I am going share\u00a0jQuery Form Selectors Examples with you for a better understanding of how the\u00a0jQuery Form Selectors work.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[79,41],"class_list":["post-922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-form-selectors","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-eS","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=922"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/922\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}